Add pg_add_size_overflow() and friends

Tom Lane <tgl@sss.pgh.pa.us>

Commit: d75b1dc96f0a15b71dd832285fafaac7a755f4cb
Author: Tom Lane <tgl@sss.pgh.pa.us>
Committer: Noah Misch <noah@leadboat.com>
Date: 2026-05-11T12:13:50Z
Releases: 15.18
Add pg_add_size_overflow() and friends

Commit 600086f47 added (several bespoke copies of) size_t addition with
overflow checks to libpq. Move this to common/int.h, along with
its subtraction and multiplication counterparts.

pg_neg_size_overflow() is intentionally omitted; I'm not sure we should
add SSIZE_MAX to win32_port.h for the sake of a function with no
callers.

Back-patch of commit 8934f2136, done now because pg_add_size_overflow()
and friends are needed more widely for security fixes.

Author: Jacob Champion <jacob.champion@enterprisedb.com>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Discussion: https://postgr.es/m/CAOYmi%2B%3D%2BpqUd2MUitvgW1pAJuXgG_TKCVc3_Ek7pe8z9nkf%2BAg%40mail.gmail.com
Backpatch-through: 14-18
Security: CVE-2026-6473

Files

PathChange+/−
src/include/common/int.h modified +67 −0
src/interfaces/libpq/fe-exec.c modified +12 −32
src/interfaces/libpq/fe-print.c modified +8 −28
src/interfaces/libpq/fe-protocol3.c modified +4 −23

Discussion