postgres.git / summary / log / commit / refs

commit    19adcaf00f7d8480f231bcfbb6b7a4401a531ce5
Author:   Tom Lane <tgl@sss.pgh.pa.us>
Date:     Mon Jan 02 21:17:00 2023 +0000
First released in: 16.0, 11.19, 12.14, 13.10, 14.7, 15.2

    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


src/backend/executor/nodeAgg.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/backend/executor/nodeAgg.c b/src/backend/executor/nodeAgg.c index 3bc78331e45..9c5d6e66a2e 100644 --- a/src/backend/executor/nodeAgg.c +++ b/src/backend/executor/nodeAgg.c @@ -3570,6 +3570,11 @@ ExecInitAgg(Agg *node, EState *estate, int eflags) { int length = phasedata->gset_lengths[i]; + /* 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; [parent: 58dcac07ed34]