pgsql: Fix auto_explain index scan NULL pointer dereference.

From: Peter Geoghegan <pg(at)bowt(dot)ie>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix auto_explain index scan NULL pointer dereference.
Date: 2026-11-19 22:53:59
Message-ID: E1xUB0w-00000000RZu-3MaM@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix auto_explain index scan NULL pointer dereference.

Commit f026fbf059f, which made IndexScanInstrumentation into a pointer
stored in various executor scan nodes, allocated the underlying
instrumentation state at the point where the executor first initialized
these nodes, though only when the plan was actually going to be run.
This scheme assumed that EXPLAIN would only need to show the relevant
counters for a plan that had actually run.

That was correct for EXPLAIN, but failed to account for
contrib/auto_explain's auto_explain.log_analyze option. This option
sets es->analyze when logging the plan of an EXPLAIN (BUFFERS) without
ANALYZE. The plan wouldn't run there, leading to a NULL pointer
dereference crash.

To fix, check that the instrumentation was allocated before using it.

Author: Xiaoxuan Li <xioxuan(at)amazon(dot)com>
Discussion: https://postgr.es/m/CANuORAZumpvu2PJwGhVWihKfmUTNcWEbknBZG5-O3aq0uuKbhw@mail.gmail.com
Backpatch-through: 19

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/a20d50a00edc40ff11b08b1e3e3be6e4f9da51f6

Modified Files
--------------
contrib/auto_explain/t/001_auto_explain.pl | 11 +++++++++++
src/backend/commands/explain.c | 13 +++++++++----
2 files changed, 20 insertions(+), 4 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Previous Message Melanie Plageman 2026-11-19 22:22:18 pgsql: Forget invalid VM pages during truncation replay