Skip to content

Commit a02740e

Browse files
committed
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
1 parent fdaba0a commit a02740e

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/backend/executor/nodeAgg.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3574,6 +3574,11 @@ ExecInitAgg(Agg *node, EState *estate, int eflags)
35743574
{
35753575
int length = phasedata->gset_lengths[i];
35763576

3577+
/* nothing to do for empty grouping set */
3578+
if (length == 0)
3579+
continue;
3580+
3581+
/* if we already had one of this length, it'll do */
35773582
if (phasedata->eqfunctions[length - 1] != NULL)
35783583
continue;
35793584

0 commit comments

Comments
 (0)