pgsql: Add error-throwing wrappers for the printf family of functions.

From: Noah Misch <noah(at)leadboat(dot)com>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Add error-throwing wrappers for the printf family of functions.
Date: 2015-05-18 14:04:02
Message-ID: E1YuLeE-00065f-Oj@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Add error-throwing wrappers for the printf family of functions.

All known standard library implementations of these functions can fail
with ENOMEM. A caller neglecting to check for failure would experience
missing output, information exposure, or a crash. Check return values
within wrappers and code, currently just snprintf.c, that bypasses the
wrappers. The wrappers do not return after an error, so their callers
need not check. Back-patch to 9.0 (all supported versions).

Popular free software standard library implementations do take pains to
bypass malloc() in simple cases, but they risk ENOMEM for floating point
numbers, positional arguments, large field widths, and large precisions.
No specification demands such caution, so this commit regards every call
to a printf family function as a potential threat.

Injecting the wrappers implicitly is a compromise between patch scope
and design goals. I would prefer to edit each call site to name a
wrapper explicitly. libpq and the ECPG libraries would, ideally, convey
errors to the caller rather than abort(). All that would be painfully
invasive for a back-patched security fix, hence this compromise.

Security: CVE-2015-3166

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/16304a013432931e61e623c8d85e9fe24709d9ba

Modified Files
--------------
src/include/port.h | 80 ++++++++++-----
src/interfaces/ecpg/compatlib/Makefile | 1 +
src/interfaces/ecpg/ecpglib/.gitignore | 1 +
src/interfaces/ecpg/ecpglib/Makefile | 6 +-
src/interfaces/ecpg/pgtypeslib/.gitignore | 1 +
src/interfaces/ecpg/pgtypeslib/Makefile | 6 +-
src/interfaces/libpq/.gitignore | 1 +
src/interfaces/libpq/Makefile | 6 +-
src/interfaces/libpq/bcc32.mak | 7 ++
src/interfaces/libpq/win32.mak | 7 ++
src/pl/plperl/plperl.h | 12 +--
src/pl/plpython/plpython.h | 12 +--
src/port/Makefile | 2 +-
src/port/snprintf.c | 94 +++++++++--------
src/port/syswrap.c | 155 +++++++++++++++++++++++++++++
src/tools/msvc/Mkvcbuild.pm | 2 +-
16 files changed, 300 insertions(+), 93 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Noah Misch 2015-05-18 14:04:03 pgsql: Permit use of vsprintf() in PostgreSQL code.
Previous Message Peter Eisentraut 2015-05-18 12:59:12 pgsql: Translation updates