aboutsummaryrefslogtreecommitdiff
path: root/src/backend/executor
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2023-01-02 16:17:00 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2023-01-02 16:17:00 -0500
commitfbed54fb3890894055072381bb13850baf524ba5 (patch)
treec9c634d40410513bd35132c1dcf5bb553fa9767c /src/backend/executor
parent1fbcb1360bc19b89369209203ea7cc19b8cde224 (diff)
downloadpostgresql-fbed54fb3890894055072381bb13850baf524ba5.tar.gz
postgresql-fbed54fb3890894055072381bb13850baf524ba5.zip
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
Diffstat (limited to 'src/backend/executor')
-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 139b2bd5f9b..d1ec337b302 100644
--- a/src/backend/executor/nodeAgg.c
+++ b/src/backend/executor/nodeAgg.c
@@ -3486,6 +3486,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;