pg.ddx.io  pgpool-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgpool: Reject negative read length in pool_read2.
6+ messages / 1 participants
[nested] [flat]

* pgpool: Reject negative read length in pool_read2.
@ 2026-09-29 10:50 Tatsuo Ishii <ishii@postgresql.org>
  0 siblings, 0 replies; 6+ messages in thread

From: Tatsuo Ishii @ 2026-09-29 10:50 UTC (permalink / raw)
  To: pgpool-committers@lists.postgresql.org

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_3_STABLE

Details
-------
https://git.postgresql.org/gitweb?p=pgpool2.git;a=commitdiff;h=5b5eafae9bd85e73fa5dd01ce180655af93fc...

Modified Files
--------------
src/utils/pool_stream.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* pgpool: Reject negative read length in pool_read2.
@ 2026-09-29 10:50 Tatsuo Ishii <ishii@postgresql.org>
  0 siblings, 0 replies; 6+ messages in thread

From: Tatsuo Ishii @ 2026-09-29 10:50 UTC (permalink / raw)
  To: pgpool-committers@lists.postgresql.org

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_4_STABLE

Details
-------
https://git.postgresql.org/gitweb?p=pgpool2.git;a=commitdiff;h=2a7eb6ed31c285c826b5c5c4c03c65749fd97...

Modified Files
--------------
src/utils/pool_stream.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* pgpool: Reject negative read length in pool_read2.
@ 2026-09-29 10:50 Tatsuo Ishii <ishii@postgresql.org>
  0 siblings, 0 replies; 6+ messages in thread

From: Tatsuo Ishii @ 2026-09-29 10:50 UTC (permalink / raw)
  To: pgpool-committers@lists.postgresql.org

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(-)



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* pgpool: Reject negative read length in pool_read2.
@ 2026-09-29 10:51 Tatsuo Ishii <ishii@postgresql.org>
  0 siblings, 0 replies; 6+ messages in thread

From: Tatsuo Ishii @ 2026-09-29 10:51 UTC (permalink / raw)
  To: pgpool-committers@lists.postgresql.org

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_6_STABLE

Details
-------
https://git.postgresql.org/gitweb?p=pgpool2.git;a=commitdiff;h=128f5773a2aae49e886d00c807500f62e0fa5...

Modified Files
--------------
src/utils/pool_stream.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* pgpool: Reject negative read length in pool_read2.
@ 2026-09-29 10:51 Tatsuo Ishii <ishii@postgresql.org>
  0 siblings, 0 replies; 6+ messages in thread

From: Tatsuo Ishii @ 2026-09-29 10:51 UTC (permalink / raw)
  To: pgpool-committers@lists.postgresql.org

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_7_STABLE

Details
-------
https://git.postgresql.org/gitweb?p=pgpool2.git;a=commitdiff;h=71487bb1c66adc36484f1a6e57eb7ee570c3c...

Modified Files
--------------
src/utils/pool_stream.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* pgpool: Reject negative read length in pool_read2.
@ 2026-09-29 10:57 Tatsuo Ishii <ishii@postgresql.org>
  0 siblings, 0 replies; 6+ messages in thread

From: Tatsuo Ishii @ 2026-09-29 10:57 UTC (permalink / raw)
  To: pgpool-committers@lists.postgresql.org

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
------
master

Details
-------
https://git.postgresql.org/gitweb?p=pgpool2.git;a=commitdiff;h=3fb1d89cea0a6d7a098ac0a8851663c1a531b...

Modified Files
--------------
src/utils/pool_stream.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)



^ permalink  raw  reply  [nested|flat] 6+ messages in thread


end of thread, other threads:[~2026-09-29 10:57 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-09-29 10:50 pgpool: Reject negative read length in pool_read2. Tatsuo Ishii <ishii@postgresql.org>
2026-09-29 10:50 pgpool: Reject negative read length in pool_read2. Tatsuo Ishii <ishii@postgresql.org>
2026-09-29 10:50 pgpool: Reject negative read length in pool_read2. Tatsuo Ishii <ishii@postgresql.org>
2026-09-29 10:51 pgpool: Reject negative read length in pool_read2. Tatsuo Ishii <ishii@postgresql.org>
2026-09-29 10:51 pgpool: Reject negative read length in pool_read2. Tatsuo Ishii <ishii@postgresql.org>
2026-09-29 10:57 pgpool: Reject negative read length in pool_read2. Tatsuo Ishii <ishii@postgresql.org>

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