From: Tatsuo Ishii <ishii@postgresql.org>
To: pgpool-committers@lists.postgresql.org
Subject: pgpool: Reject negative read length in pool_read2.
Date: Tue, 29 Sep 2026 10:50:58 +0000
Message-ID: <E1xBVQI-00000006E3r-1FKm@gothos.postgresql.org> (raw)
Reject negative read length in pool_read2.
pool_read2() allocates buf2 sized to cp->len + len, consumes that many
bytes from the pending buffer, then loops reading from the socket
while len > 0. When len is zero or negative the loop never executes a
fresh read and the function falls straight through to "return
cp->buf2", handing the caller a pointer to whatever the previous
pool_read2() invocation happened to leave in the per-connection
buffer.
Callers compute len from on-the-wire length fields, e.g.
len = ntohl(hdr) - sizeof(hdr);
and several do so without bounds-checking. A backend that ships a
malformed message with a length smaller than the header (or a
negative value once cast to int32) drives pool_read2() into the
stale-buffer path. The stale bytes are then forwarded to the
frontend as ParameterStatus / ErrorResponse / etc. payloads,
leaking whatever the previous reply contained on this same
backend connection.
Add a guard at the top of pool_read2() that logs and returns NULL when
len < 0, before any buffer setup runs.
When len == 0, just retuns cp->buf2, rather than returning NULL to not
break existing callers relying on the behavior.
Reported-by: Emond Papegaaij <emond.papegaaij@gmail.com>
Reported-by: Claude code
Author: Tatsuo Ishii <ishii@postgresql.org>
Discussion: https://github.com/pgpool/pgpool2/issues/168
Backpatch-through: v4.3
Branch
------
V4_5_STABLE
Details
-------
https://git.postgresql.org/gitweb?p=pgpool2.git;a=commitdiff;h=383ef5979c7b01c7132a6ac78fe40b7be29d6...
Modified Files
--------------
src/utils/pool_stream.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgpool-committers@postgresql.org
Cc: ishii@postgresql.org
Subject: Re: pgpool: Reject negative read length in pool_read2.
In-Reply-To: <E1xBVQI-00000006E3r-1FKm@gothos.postgresql.org>
References: <E1xBVQI-00000006E3r-1FKm@gothos.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