mirror of
https://github.com/postgres/postgres.git
synced 2025-07-07 00:36:50 +03:00
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
This commit is contained in:
@ -37,10 +37,8 @@
|
||||
* So we undefine them here and redefine them after it's done its dirty deed.
|
||||
*/
|
||||
|
||||
#ifdef USE_REPL_SNPRINTF
|
||||
#undef snprintf
|
||||
#undef vsnprintf
|
||||
#endif
|
||||
|
||||
|
||||
/* required for perl API */
|
||||
@ -49,7 +47,6 @@
|
||||
#include "XSUB.h"
|
||||
|
||||
/* put back our snprintf and vsnprintf */
|
||||
#ifdef USE_REPL_SNPRINTF
|
||||
#ifdef snprintf
|
||||
#undef snprintf
|
||||
#endif
|
||||
@ -57,13 +54,12 @@
|
||||
#undef vsnprintf
|
||||
#endif
|
||||
#ifdef __GNUC__
|
||||
#define vsnprintf(...) pg_vsnprintf(__VA_ARGS__)
|
||||
#define snprintf(...) pg_snprintf(__VA_ARGS__)
|
||||
#define vsnprintf(...) vsnprintf_throw_on_fail(__VA_ARGS__)
|
||||
#define snprintf(...) snprintf_throw_on_fail(__VA_ARGS__)
|
||||
#else
|
||||
#define vsnprintf pg_vsnprintf
|
||||
#define snprintf pg_snprintf
|
||||
#define vsnprintf vsnprintf_throw_on_fail
|
||||
#define snprintf snprintf_throw_on_fail
|
||||
#endif /* __GNUC__ */
|
||||
#endif /* USE_REPL_SNPRINTF */
|
||||
|
||||
/* perl version and platform portability */
|
||||
#define NEED_eval_pv
|
||||
|
Reference in New Issue
Block a user