summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane2023-01-02 21:17:00 +0000
committerTom Lane2023-01-02 21:17:00 +0000
commit92957ed98c5c565362ce665266132a7f08f6b0c0 (patch)
tree0a11f64860c4c2f4ff562725640690c0699b2c8f
parentc8e1ba736b2b9e8c98d37a5b77c4ed31baf94147 (diff)
Avoid reference to nonexistent array element in ExecInitAgg().
When considering an empty grouping set, we fetched phasedata->eqfunctions[-1]. Because the eqfunctions array is palloc'd, that would always be an aset pointer in released versions, and thus the code accidentally failed to malfunction (since it would do nothing unless it found a null pointer). Nonetheless this seems like trouble waiting to happen, so add a check for length == 0. It's depressing that our valgrind testing did not catch this. Maybe we should reconsider the choice to not mark that word NOACCESS? Richard Guo Discussion: https://postgr.es/m/CAMbWs4-vZuuPOZsKOYnSAaPYGKhmacxhki+vpOKk0O7rymccXQ@mail.gmail.com
-rw-r--r--src/backend/executor/nodeAgg.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/backend/executor/nodeAgg.c b/src/backend/executor/nodeAgg.c
index 9789e67ec5..dfbac96839 100644
--- a/src/backend/executor/nodeAgg.c
+++ b/src/backend/executor/nodeAgg.c
@@ -3494,6 +3494,11 @@ ExecInitAgg(Agg *node, EState *estate, int eflags)
{
int length = phasedata->gset_lengths[k];
+ /* nothing to do for empty grouping set */
+ if (length == 0)
+ continue;
+
+ /* if we already had one of this length, it'll do */
if (phasedata->eqfunctions[length - 1] != NULL)
continue;