pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Fujii Masao <fujii@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: psql: Avoid returning oom_buffer from psql slash option scanner
Date: Wed, 19 Aug 2026 03:40:06 +0000
Message-ID: <E1wwX9p-000000019S8-03EO@gemulon.postgresql.org> (raw)

psql: Avoid returning oom_buffer from psql slash option scanner

psql_scan_slash_option() builds option text in a local PQExpBufferData
and returns the buffer's data pointer to its caller. If either the initial
allocation or a later enlargement failed, that data pointer could be
the static PQExpBuffer OOM buffer rather than malloc-owned storage.
The callers could then eventually pass it to free(), causing undefined
behavior.

Detect a broken option buffer before returning it, report OOM, and return
NULL instead. Also avoid evaluating a backtick substitution when the option
buffer is already broken, since doing so could otherwise touch the static
OOM buffer.

This keeps the existing NULL-return convention for slash options. Callers
are not generally changed to distinguish OOM from no option.

Backpatch to all supported versions.

Reported-by: Junwang Zhao <zhjwpku@gmail.com>
Author: Fujii Masao <masao.fujii@gmail.com>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Reviewed-by: Junwang Zhao <zhjwpku@gmail.com>
Discussion: https://postgr.es/m/CAHGQGwEh3R3=1tx_a5=fTDJ+ycuwxWMEn6bG_Yt4B5P+hE7AVw@mail.gmail.com
Backpatch-through: 14

Branch
------
REL_19_STABLE

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

Modified Files
--------------
src/bin/psql/command.c       |  2 +-
src/bin/psql/psqlscanslash.l | 24 ++++++++++++++++++++++--
2 files changed, 23 insertions(+), 3 deletions(-)



view thread (14+ messages)  latest in thread

Message-ID: <E1wwX9p-000000019S8-03EO@gemulon.postgresql.org>
Permalink:  ../E1wwX9p-000000019S8-03EO@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1wwX9p-000000019S8-03EO@gemulon.postgresql.org

 · 

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: pgsql-committers@postgresql.org
  Cc: fujii@postgresql.org, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: psql: Avoid returning oom_buffer from psql slash option scanner
  In-Reply-To: <E1wwX9p-000000019S8-03EO@gemulon.postgresql.org>

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

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