]> git.ipfire.org Git - thirdparty/postgresql.git/commit
pg_stat_statements: Fix potential use-after-free of PlannedStmt
authorMichael Paquier <michael@paquier.xyz>
Tue, 12 May 2026 04:36:38 +0000 (13:36 +0900)
committerMichael Paquier <michael@paquier.xyz>
Tue, 12 May 2026 04:36:38 +0000 (13:36 +0900)
commit8268e41aca23ae3414360b0a1dc6ae99ea7b43f4
tree40231411b852a0a12353f0cb68d15a7b01daa985
parent8974a7c433d363b729c5b2379ff849e2e60dffbe
pg_stat_statements: Fix potential use-after-free of PlannedStmt

pgss_ProcessUtility() included a reference to a portion of a PlannedStmt
after the point where this data's structure could have been freed,
causing an incorrect memory access.  There was a comment documenting
this requirement, missed in 3357471cf9f5.

This commit includes a test able to make valgrind complain with a
PlannedStmt freed by an internal ROLLBACK query.  Similarly to what is
mentioned in 495e73c2079e, this can be triggered by using the extended
query protocol, something that can be now tested thanks to the recent
meta-command additions in psql.  This commit mentions potential other
cases, but as far as I can see the extended protocol case with an
internal ROLLBACK is the only problematic pattern reachable in practice.

Issue introduced by 3357471cf9f5, gone unnoticed due to a lack of test
coverage.  The fix is authored by Chao, my contribution being the new
test.

Author: Chao Li <li.evan.chao@gmail.com>
Co-authored-by: Michael Paquier <michael@paquier.xyz>
Discussion: https://postgr.es/m/2F91906A-F2B5-4A6B-9695-D136957D4545@gmail.com
contrib/pg_stat_statements/expected/plancache.out
contrib/pg_stat_statements/pg_stat_statements.c
contrib/pg_stat_statements/sql/plancache.sql