pg_stat_statements: Fix buffer overflow with query normalization

Since commit 62d712ecfd94, pg_stat_statements has been underestimating
the size of the result buffer possible for a normalized query, in cases
where the query includes many squashable lists, causing the normalized
query to write past the allocated area.

The allocated buffer size forgot to account for the comment appended in
a squashable list, "/*, ... */".  Instead of trying to track down
precisely how much space we need, fix by switch to using an expansible
StringInfo.  This not only fixes the bug, but it also makes the code
simpler to follow.

Author: Álvaro Herrera <[email protected]>
Reported-by: Sajeeb Lohani with TrendAI Zero Day Initiative
Reported-by: Yuelin Wang <[email protected]>
Diagnosed-by: Michaël Paquier <[email protected]>
Backpatch-through: 18
Security: CVE-2026-14676
Discussion: https://postgr.es/m/[email protected]

Branch
------
REL_18_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/8a31ffc2d4cc5e2f3fb42b6a41b7db802716615d
Author: Álvaro Herrera <[email protected]>

Modified Files
--------------
contrib/pg_stat_statements/pg_stat_statements.c | 45 ++++++++++---------------
1 file changed, 17 insertions(+), 28 deletions(-)

Reply via email to