]> git.ipfire.org Git - thirdparty/postgresql.git/commit
libpq: Prevent some overflows of int/size_t
authorJacob Champion <jchampion@postgresql.org>
Mon, 10 Nov 2025 14:03:05 +0000 (06:03 -0800)
committerJacob Champion <jchampion@postgresql.org>
Mon, 10 Nov 2025 14:03:05 +0000 (06:03 -0800)
commit91421565febbf99c1ea2341070878dc50ab0afef
treea7c2bed507990be758a4d949a42fa582d3554f98
parent86cbe9effe102d0d88184d467ec1598a028626af
libpq: Prevent some overflows of int/size_t

Several functions could overflow their size calculations, when presented
with very large inputs from remote and/or untrusted locations, and then
allocate buffers that were too small to hold the intended contents.

Switch from int to size_t where appropriate, and check for overflow
conditions when the inputs could have plausibly originated outside of
the libpq trust boundary. (Overflows from within the trust boundary are
still possible, but these will be fixed separately.) A version of
add_size() is ported from the backend to assist with code that performs
more complicated concatenation.

Reported-by: Aleksey Solovev (Positive Technologies)
Reviewed-by: Noah Misch <noah@leadboat.com>
Reviewed-by: Álvaro Herrera <alvherre@kurilemu.de>
Security: CVE-2025-12818
Backpatch-through: 13
src/interfaces/libpq/fe-connect.c
src/interfaces/libpq/fe-exec.c
src/interfaces/libpq/fe-print.c
src/interfaces/libpq/fe-protocol3.c
src/interfaces/libpq/libpq-int.h