summaryrefslogtreecommitdiff
path: root/src/interfaces/libpq/libpq-int.h
diff options
context:
space:
mode:
authorJacob Champion <jchampion@postgresql.org>2025-11-10 06:02:34 -0800
committerJacob Champion <jchampion@postgresql.org>2025-11-10 06:20:33 -0800
commit600086f471a3bb57ff4953accf1d3f8d2efe0201 (patch)
treec164307cfe8e45486fc613d5147ccf73404ce618 /src/interfaces/libpq/libpq-int.h
parent3e0ae46d907dd5f36342dd288841f4502bd571f6 (diff)
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
Diffstat (limited to 'src/interfaces/libpq/libpq-int.h')
-rw-r--r--src/interfaces/libpq/libpq-int.h11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/interfaces/libpq/libpq-int.h b/src/interfaces/libpq/libpq-int.h
index 02c114f1405..0f3661b8889 100644
--- a/src/interfaces/libpq/libpq-int.h
+++ b/src/interfaces/libpq/libpq-int.h
@@ -563,7 +563,16 @@ struct pg_conn
pg_prng_state prng_state; /* prng state for load balancing connections */
- /* Buffer for data received from backend and not yet processed */
+ /*
+ * Buffer for data received from backend and not yet processed.
+ *
+ * NB: We rely on a maximum inBufSize/outBufSize of INT_MAX (and therefore
+ * an INT_MAX upper bound on the size of any and all packet contents) to
+ * avoid overflow; for example in reportErrorPosition(). Changing the type
+ * would require not only an adjustment to the overflow protection in
+ * pqCheck{In,Out}BufferSpace(), but also a careful audit of all libpq
+ * code that uses ints during size calculations.
+ */
char *inBuffer; /* currently allocated buffer */
int inBufSize; /* allocated size of buffer */
int inStart; /* offset to first unconsumed data in buffer */