summaryrefslogtreecommitdiff
path: root/src/pl/plperl/plperl.h
diff options
context:
space:
mode:
authorNoah Misch <noah@leadboat.com>2015-05-18 10:02:31 -0400
committerNoah Misch <noah@leadboat.com>2015-05-18 10:02:36 -0400
commit34d21e77081c6a3d1fb7d8b76d6a2dcef9874efe (patch)
treec1eae2ac8ce5e2932715d27772c5978add8b7693 /src/pl/plperl/plperl.h
parentd5abbd11479d1bc2e1439d3764251f9cb3b60755 (diff)
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
Diffstat (limited to 'src/pl/plperl/plperl.h')
-rw-r--r--src/pl/plperl/plperl.h12
1 files changed, 4 insertions, 8 deletions
diff --git a/src/pl/plperl/plperl.h b/src/pl/plperl/plperl.h
index c86b47e9d23..208d79571bb 100644
--- a/src/pl/plperl/plperl.h
+++ b/src/pl/plperl/plperl.h
@@ -39,10 +39,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 */
@@ -51,7 +49,6 @@
#include "XSUB.h"
/* put back our snprintf and vsnprintf */
-#ifdef USE_REPL_SNPRINTF
#ifdef snprintf
#undef snprintf
#endif
@@ -59,13 +56,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