Avoid reference to nonexistent array element in ExecInitAgg().

Tom Lane <tgl@sss.pgh.pa.us>

Commit: 039567eb57ee5a5ab1a2ad2352316b2d31e7150e
Author: Tom Lane <tgl@sss.pgh.pa.us>
Date: 2023-01-02T21:17:00Z
Releases: 12.14
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

Files

PathChange+/−
src/backend/executor/nodeAgg.c modified +5 −0

Discussion