diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2015-05-19 18:14:52 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2015-05-19 18:19:38 -0400 |
commit | 0c071936e94c6859afb2ec8d2c8dddf7bcdab7ee (patch) | |
tree | 99fa4dc83085ce53f25ba52f84734fded163d78a /src/port/syswrap.c | |
parent | 9bc77c45199c7d2e525cd5b1457d5a57f6e9edb0 (diff) | |
download | postgresql-0c071936e94c6859afb2ec8d2c8dddf7bcdab7ee.tar.gz postgresql-0c071936e94c6859afb2ec8d2c8dddf7bcdab7ee.zip |
Revert error-throwing wrappers for the printf family of functions.
This reverts commit 16304a013432931e61e623c8d85e9fe24709d9ba, except
for its changes in src/port/snprintf.c; as well as commit
cac18a76bb6b08f1ecc2a85e46c9d2ab82dd9d23 which is no longer needed.
Fujii Masao reported that the previous commit caused failures in psql on
OS X, since if one exits the pager program early while viewing a query
result, psql sees an EPIPE error from fprintf --- and the wrapper function
thought that was reason to panic. (It's a bit surprising that the same
does not happen on Linux.) Further discussion among the security list
concluded that the risk of other such failures was far too great, and
that the one-size-fits-all approach to error handling embodied in the
previous patch is unlikely to be workable.
This leaves us again exposed to the possibility of the type of failure
envisioned in CVE-2015-3166. However, that failure mode is strictly
hypothetical at this point: there is no concrete reason to believe that
an attacker could trigger information disclosure through the supposed
mechanism. In the first place, the attack surface is fairly limited,
since so much of what the backend does with format strings goes through
stringinfo.c or psprintf(), and those already had adequate defenses.
In the second place, even granting that an unprivileged attacker could
control the occurrence of ENOMEM with some precision, it's a stretch to
believe that he could induce it just where the target buffer contains some
valuable information. So we concluded that the risk of non-hypothetical
problems induced by the patch greatly outweighs the security risks.
We will therefore revert, and instead undertake closer analysis to
identify specific calls that may need hardening, rather than attempt a
universal solution.
We have kept the portion of the previous patch that improved snprintf.c's
handling of errors when it calls the platform's sprintf(). That seems to
be an unalloyed improvement.
Security: CVE-2015-3166
Diffstat (limited to 'src/port/syswrap.c')
-rw-r--r-- | src/port/syswrap.c | 155 |
1 files changed, 0 insertions, 155 deletions
diff --git a/src/port/syswrap.c b/src/port/syswrap.c deleted file mode 100644 index 8415a336303..00000000000 --- a/src/port/syswrap.c +++ /dev/null @@ -1,155 +0,0 @@ -/*------------------------------------------------------------------------- - * - * syswrap.c - * error-throwing wrappers around POSIX functions that rarely fail - * - * Portions Copyright (c) 1996-2015, PostgreSQL Global Development Group - * - * - * IDENTIFICATION - * src/port/syswrap.c - * - *------------------------------------------------------------------------- - */ - -#ifndef FRONTEND -#include "postgres.h" -#else -#include "postgres_fe.h" -#endif - -/* Prevent recursion */ -#undef vsnprintf -#undef snprintf -#undef vsprintf -#undef sprintf -#undef vfprintf -#undef fprintf -#undef printf - -/* When the libc primitives are lacking, use our own. */ -#ifdef USE_REPL_SNPRINTF -#ifdef __GNUC__ -#define vsnprintf(...) pg_vsnprintf(__VA_ARGS__) -#define snprintf(...) pg_snprintf(__VA_ARGS__) -#define vsprintf(...) pg_vsprintf(__VA_ARGS__) -#define sprintf(...) pg_sprintf(__VA_ARGS__) -#define vfprintf(...) pg_vfprintf(__VA_ARGS__) -#define fprintf(...) pg_fprintf(__VA_ARGS__) -#define printf(...) pg_printf(__VA_ARGS__) -#else -#define vsnprintf pg_vsnprintf -#define snprintf pg_snprintf -#define vsprintf pg_vsprintf -#define sprintf pg_sprintf -#define vfprintf pg_vfprintf -#define fprintf pg_fprintf -#define printf pg_printf -#endif -#endif /* USE_REPL_SNPRINTF */ - -/* - * We abort() in the frontend, rather than exit(), because libpq in particular - * has no business calling exit(). These failures had better be rare. - */ -#ifdef FRONTEND -#define LIB_ERR(func) \ -do { \ - int discard = fprintf(stderr, "%s failed: %s\n", func, strerror(errno)); \ - (void) discard; \ - abort(); \ -} while (0) -#else -#define LIB_ERR(func) elog(ERROR, "%s failed: %m", func) -#endif - -int -vsnprintf_throw_on_fail(char *str, size_t count, const char *fmt, va_list args) -{ - int save_errno; - int ret; - - /* - * On HP-UX B.11.31, a call that truncates output returns -1 without - * setting errno. (SUSv2 allowed this until the approval of Base Working - * Group Resolution BWG98-006.) We could avoid the save and restore of - * errno on most platforms. - */ - save_errno = errno; - errno = 0; - ret = vsnprintf(str, count, fmt, args); - if (ret < 0 && errno != 0) - LIB_ERR("vsnprintf"); - errno = save_errno; - return ret; -} - -int -snprintf_throw_on_fail(char *str, size_t count, const char *fmt,...) -{ - int ret; - va_list args; - - va_start(args, fmt); - ret = vsnprintf_throw_on_fail(str, count, fmt, args); - va_end(args); - return ret; -} - -int -vsprintf_throw_on_fail(char *str, const char *fmt, va_list args) -{ - int ret; - - ret = vsprintf(str, fmt, args); - if (ret < 0) - LIB_ERR("vsprintf"); - return ret; -} - -int -sprintf_throw_on_fail(char *str, const char *fmt,...) -{ - int ret; - va_list args; - - va_start(args, fmt); - ret = vsprintf_throw_on_fail(str, fmt, args); - va_end(args); - return ret; -} - -int -vfprintf_throw_on_fail(FILE *stream, const char *fmt, va_list args) -{ - int ret; - - ret = vfprintf(stream, fmt, args); - if (ret < 0) - LIB_ERR("vfprintf"); - return ret; -} - -int -fprintf_throw_on_fail(FILE *stream, const char *fmt,...) -{ - int ret; - va_list args; - - va_start(args, fmt); - ret = vfprintf_throw_on_fail(stream, fmt, args); - va_end(args); - return ret; -} - -int -printf_throw_on_fail(const char *fmt,...) -{ - int ret; - va_list args; - - va_start(args, fmt); - ret = vfprintf_throw_on_fail(stdout, fmt, args); - va_end(args); - return ret; -} |