public inbox for [email protected]  
help / color / mirror / Atom feed
From: Andres Freund <[email protected]>
To: [email protected]
To: Michael Paquier <[email protected]>
To: Chao Li <[email protected]>
Cc: PostgreSQL Hackers <[email protected]>
Subject: Re: Fix unsafe PlannedStmt access in pg_stat_statements
Date: Tue, 12 May 2026 11:00:16 +0200
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>
	<[email protected]>
	<[email protected]>

Hi, 

On May 12, 2026 5:30:53 AM GMT+02:00, Michael Paquier <[email protected]> wrote:
>On Mon, May 11, 2026 at 04:11:41PM +0800, Chao Li wrote:
>> On May 11, 2026, at 16:07, Chao Li <[email protected]> wrote:
>>> In pgss_ProcessUtility(), there is this comment:
>>> ```
>>> /*
>>> * CAUTION: do not access the *pstmt data structure again below here.
>>> * If it was a ROLLBACK or similar, that data structure may have been
>>> * freed.  We must copy everything we still need into local variables,
>>> * which we did above.
>>> *
>>> * For the same reason, we can't risk restoring pstmt->queryId to its
>>> * former value, which'd otherwise be a good idea.
>>> */
>>> ```
>>> 
>>> The attached patch fixes this by saving pstmt->planOrigin,
>>> following the same pattern already used for queryId, stmt_location,
>>> and stmt_len.
>
>Yeah, you are right.  This code should save the planOrigin but it does
>not do so.

Seems like the code should make this clearer, by simply unsetting pstmt at the point it becomes unsafe to use? 


Andres





view thread (8+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected], [email protected]
  Subject: Re: Fix unsafe PlannedStmt access in pg_stat_statements
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox