Re: Fix unsafe PlannedStmt access in pg_stat_statements

Michael Paquier <michael@paquier.xyz>

From: Michael Paquier <michael@paquier.xyz>
To: Chao Li <li.evan.chao@gmail.com>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2026-05-11T08:11:45Z
Lists: pgsql-hackers

Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. pg_stat_statements: Set PlannedStmt to NULL after nested utility execution

  2. pg_stat_statements: Fix potential use-after-free of PlannedStmt

  3. pg_stat_statements: Add counters for generic and custom plans

On Mon, May 11, 2026 at 04:07:29PM +0800, Chao Li wrote:
> However, commit 3357471cf9f5e470dfed0c7919bcf31c7efaf2b9 added a new
> access to pstmt after that point:
> 
> The attached patch fixes this by saving pstmt->planOrigin, following
> the same pattern already used for queryId, stmt_location, and
> stmt_len.

That would be my business.  Missing a patch attached perhaps?
--
Michael