Revert error-throwing wrappers for the printf family of functions.
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 19 May 2015 22:16:58 +0000 (18:16 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 19 May 2015 22:16:58 +0000 (18:16 -0400)
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

16 files changed:
src/include/port.h
src/interfaces/ecpg/compatlib/Makefile
src/interfaces/ecpg/ecpglib/.gitignore
src/interfaces/ecpg/ecpglib/Makefile
src/interfaces/ecpg/pgtypeslib/.gitignore
src/interfaces/ecpg/pgtypeslib/Makefile
src/interfaces/libpq/.gitignore
src/interfaces/libpq/Makefile
src/interfaces/libpq/bcc32.mak
src/interfaces/libpq/win32.mak
src/pl/plperl/plperl.h
src/pl/plpython/plpython.h
src/port/Makefile
src/port/snprintf.c
src/port/syswrap.c [deleted file]
src/tools/msvc/Mkvcbuild.pm

index 4f2c654c68d6ad78539ee5b184db02133ee0e546..cdcc19a32c5ac57b534da5dd24e5df4f39b4bff9 100644 (file)
@@ -156,11 +156,12 @@ extern unsigned char pg_tolower(unsigned char ch);
 extern unsigned char pg_ascii_toupper(unsigned char ch);
 extern unsigned char pg_ascii_tolower(unsigned char ch);
 
+#ifdef USE_REPL_SNPRINTF
+
 /*
- * Capture macro-compatible calls to printf() and friends, and redirect them
- * to wrappers that throw errors in lieu of reporting failure in a return
- * value.  Versions of libintl >= 0.13 similarly redirect to versions that
- * understand the %$ format, so disable libintl macros first.
+ * Versions of libintl >= 0.13 try to replace printf() and friends with
+ * macros to their own versions that understand the %$ format.  We do the
+ * same, so disable their macros, if they exist.
  */
 #ifdef vsnprintf
 #undef vsnprintf
@@ -168,9 +169,6 @@ extern unsigned char pg_ascii_tolower(unsigned char ch);
 #ifdef snprintf
 #undef snprintf
 #endif
-#ifdef vsprintf
-#undef vsprintf
-#endif
 #ifdef sprintf
 #undef sprintf
 #endif
@@ -184,61 +182,11 @@ extern unsigned char pg_ascii_tolower(unsigned char ch);
 #undef printf
 #endif
 
-extern int
-vsnprintf_throw_on_fail(char *str, size_t count, const char *fmt, va_list args)
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 0)));
-extern int
-snprintf_throw_on_fail(char *str, size_t count, const char *fmt,...)
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 4)));
-extern int
-vsprintf_throw_on_fail(char *str, const char *fmt, va_list args)
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 0)));
-extern int
-sprintf_throw_on_fail(char *str, const char *fmt,...)
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
-extern int
-vfprintf_throw_on_fail(FILE *stream, const char *fmt, va_list args)
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 0)));
-extern int
-fprintf_throw_on_fail(FILE *stream, const char *fmt,...)
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
-extern int
-printf_throw_on_fail(const char *fmt,...)
-__attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
-
-/*
- * The GCC-specific code below prevents the __attribute__(... 'printf')
- * above from being replaced, and this is required because gcc doesn't
- * know anything about printf_throw_on_fail.
- */
-#ifdef __GNUC__
-#define vsnprintf(...) vsnprintf_throw_on_fail(__VA_ARGS__)
-#define snprintf(...)  snprintf_throw_on_fail(__VA_ARGS__)
-#define vsprintf(...)  vsprintf_throw_on_fail(__VA_ARGS__)
-#define sprintf(...)   sprintf_throw_on_fail(__VA_ARGS__)
-#define vfprintf(...)  vfprintf_throw_on_fail(__VA_ARGS__)
-#define fprintf(...)   fprintf_throw_on_fail(__VA_ARGS__)
-#define printf(...)        printf_throw_on_fail(__VA_ARGS__)
-#else
-#define vsnprintf      vsnprintf_throw_on_fail
-#define snprintf       snprintf_throw_on_fail
-#define vsprintf       vsprintf_throw_on_fail
-#define sprintf            sprintf_throw_on_fail
-#define vfprintf       vfprintf_throw_on_fail
-#define fprintf            fprintf_throw_on_fail
-#define printf         printf_throw_on_fail
-#endif
-
-#ifdef USE_REPL_SNPRINTF
-
-/* Code outside syswrap.c should not call these. */
-
 extern int pg_vsnprintf(char *str, size_t count, const char *fmt, va_list args);
 extern int
 pg_snprintf(char *str, size_t count, const char *fmt,...)
 /* This extension allows gcc to check the format string */
 __attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 4)));
-extern int pg_vsprintf(char *str, const char *fmt, va_list args);
 extern int
 pg_sprintf(char *str, const char *fmt,...)
 /* This extension allows gcc to check the format string */
@@ -253,6 +201,26 @@ pg_printf(const char *fmt,...)
 /* This extension allows gcc to check the format string */
 __attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
 
+/*
+ * The GCC-specific code below prevents the __attribute__(... 'printf')
+ * above from being replaced, and this is required because gcc doesn't
+ * know anything about pg_printf.
+ */
+#ifdef __GNUC__
+#define vsnprintf(...) pg_vsnprintf(__VA_ARGS__)
+#define snprintf(...)  pg_snprintf(__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 sprintf            pg_sprintf
+#define vfprintf       pg_vfprintf
+#define fprintf            pg_fprintf
+#define printf         pg_printf
+#endif
 #endif   /* USE_REPL_SNPRINTF */
 
 #if defined(WIN32)
index 731148a782e625159e7aaa2512509e7a0d1d2eb0..ca489d32b94d6c6eec4bc21fe2b048dc8f97f371 100644 (file)
@@ -47,7 +47,6 @@ submake-pgtypeslib:
 # Shared library stuff
 include $(top_srcdir)/src/Makefile.shlib
 
-# XXX This library uses no symbols from snprintf.c.
 snprintf.c: % : $(top_srcdir)/src/port/%
    rm -f $@ && $(LN_S) $< .
 
index 9d994c160d407d6664857733fa6cdaeb1000433d..351f43775e88f429366baa689272aa6144d3bae6 100644 (file)
@@ -5,5 +5,4 @@
 /path.c
 /pgstrcasecmp.c
 /strlcpy.c
-/syswrap.c
 /thread.c
index e0b6c42487a2c7d366a700d003276614a5175339..86dbdc221459bd1750d081943335f8b0103204b8 100644 (file)
@@ -25,7 +25,7 @@ override CFLAGS += $(PTHREAD_CFLAGS)
 LIBS := $(filter-out -lpgport, $(LIBS))
 
 OBJS= execute.o typename.o descriptor.o sqlda.o data.o error.o prepare.o memory.o \
-   connect.o misc.o path.o pgstrcasecmp.o syswrap.o \
+   connect.o misc.o path.o pgstrcasecmp.o \
    $(filter snprintf.o strlcpy.o win32setlocale.o isinf.o, $(LIBOBJS))
 
 # thread.c is needed only for non-WIN32 implementation of path.c
@@ -59,7 +59,7 @@ include $(top_srcdir)/src/Makefile.shlib
 # necessarily use the same object files as the backend uses. Instead,
 # symlink the source files in here and build our own object file.
 
-path.c pgstrcasecmp.c snprintf.c strlcpy.c syswrap.c thread.c win32setlocale.c isinf.c: % : $(top_srcdir)/src/port/%
+path.c pgstrcasecmp.c snprintf.c strlcpy.c thread.c win32setlocale.c isinf.c: % : $(top_srcdir)/src/port/%
    rm -f $@ && $(LN_S) $< .
 
 misc.o: misc.c $(top_builddir)/src/port/pg_config_paths.h
@@ -76,6 +76,6 @@ uninstall: uninstall-lib
 
 clean distclean: clean-lib
    rm -f $(OBJS)
-   rm -f path.c pgstrcasecmp.c snprintf.c strlcpy.c syswrap.c thread.c win32setlocale.c
+   rm -f path.c pgstrcasecmp.c snprintf.c strlcpy.c thread.c win32setlocale.c
 
 maintainer-clean: distclean maintainer-clean-lib
index 4f97502100e7d5c144128caf65d66fe9082908f4..4ee58ea957eed2d6b40c2b57ae2fca40f8509284 100644 (file)
@@ -3,4 +3,3 @@
 /exports.list
 
 /pgstrcasecmp.c
-/syswrap.c
index a61245397969f49ffcea96222c8f980986e7aad6..340bef398bd9b8a57bb178163ec17746f541f8ad 100644 (file)
@@ -29,7 +29,7 @@ SHLIB_LINK += -lm
 SHLIB_EXPORTS = exports.txt
 
 OBJS= numeric.o datetime.o common.o dt_common.o timestamp.o interval.o \
-   pgstrcasecmp.o syswrap.o \
+   pgstrcasecmp.o \
    $(filter rint.o snprintf.o, $(LIBOBJS))
 
 all: all-lib
@@ -42,7 +42,7 @@ include $(top_srcdir)/src/Makefile.shlib
 # necessarily use the same object files as the backend uses. Instead,
 # symlink the source files in here and build our own object file.
 
-pgstrcasecmp.c rint.c snprintf.c syswrap.c: % : $(top_srcdir)/src/port/%
+pgstrcasecmp.c rint.c snprintf.c: % : $(top_srcdir)/src/port/%
    rm -f $@ && $(LN_S) $< .
 
 install: all installdirs install-lib
@@ -52,6 +52,6 @@ installdirs: installdirs-lib
 uninstall: uninstall-lib
 
 clean distclean: clean-lib
-   rm -f $(OBJS) pgstrcasecmp.c rint.c snprintf.c syswrap.c
+   rm -f $(OBJS) pgstrcasecmp.c rint.c snprintf.c
 
 maintainer-clean: distclean maintainer-clean-lib
index 12566fe07310f0f7ae267eebe992e6a9fa457f9d..9bd4177101c9b875834d893f827ecb2d523346da 100644 (file)
@@ -12,7 +12,6 @@
 /snprintf.c
 /strerror.c
 /strlcpy.c
-/syswrap.c
 /thread.c
 /win32error.c
 /win32setlocale.c
index 6cb6a5293e7e68d271af272e7018c27c0122f2b5..fdb30302aecfd680a488239a33b2e53ba24d25c6 100644 (file)
@@ -36,7 +36,7 @@ OBJS= fe-auth.o fe-connect.o fe-exec.o fe-misc.o fe-print.o fe-lobj.o \
    libpq-events.o
 # libpgport C files we always use
 OBJS += chklocale.o inet_net_ntop.o noblock.o pgstrcasecmp.o pqsignal.o \
-   syswrap.o thread.o
+   thread.o
 # libpgport C files that are needed if identified by configure
 OBJS += $(filter crypt.o getaddrinfo.o getpeereid.o inet_aton.o open.o snprintf.o strerror.o strlcpy.o win32error.o win32setlocale.o, $(LIBOBJS))
 # backend/libpq
@@ -89,7 +89,7 @@ backend_src = $(top_srcdir)/src/backend
 # For some libpgport modules, this only happens if configure decides
 # the module is needed (see filter hack in OBJS, above).
 
-chklocale.c crypt.c getaddrinfo.c getpeereid.c inet_aton.c inet_net_ntop.c noblock.c open.c pgsleep.c pgstrcasecmp.c pqsignal.c snprintf.c strerror.c strlcpy.c syswrap.c thread.c win32error.c win32setlocale.c: % : $(top_srcdir)/src/port/%
+chklocale.c crypt.c getaddrinfo.c getpeereid.c inet_aton.c inet_net_ntop.c noblock.c open.c pgsleep.c pgstrcasecmp.c pqsignal.c snprintf.c strerror.c strlcpy.c thread.c win32error.c win32setlocale.c: % : $(top_srcdir)/src/port/%
    rm -f $@ && $(LN_S) $< .
 
 ip.c md5.c: % : $(backend_src)/libpq/%
@@ -150,7 +150,7 @@ clean distclean: clean-lib
 # Might be left over from a Win32 client-only build
    rm -f pg_config_paths.h
    rm -f inet_net_ntop.c noblock.c pgstrcasecmp.c pqsignal.c thread.c
-   rm -f chklocale.c crypt.c getaddrinfo.c getpeereid.c inet_aton.c open.c snprintf.c strerror.c strlcpy.c syswrap.c win32error.c win32setlocale.c
+   rm -f chklocale.c crypt.c getaddrinfo.c getpeereid.c inet_aton.c open.c snprintf.c strerror.c strlcpy.c win32error.c win32setlocale.c
    rm -f pgsleep.c
    rm -f md5.c ip.c
    rm -f encnames.c wchar.c
index 31944b18b05b9fb0b39a7c03c4ff33f0cdd0b6ea..8f5cd8de470d24f6f39f629c24bbcd0a6324c0f7 100644 (file)
@@ -106,7 +106,6 @@ CLEAN :
    -@erase "$(INTDIR)\dirmod.obj"
    -@erase "$(INTDIR)\pgsleep.obj"
    -@erase "$(INTDIR)\open.obj"
-   -@erase "$(INTDIR)\syswrap.obj"
    -@erase "$(INTDIR)\win32error.obj"
    -@erase "$(OUTDIR)\$(OUTFILENAME).lib"
    -@erase "$(OUTDIR)\$(OUTFILENAME)dll.lib"
@@ -150,7 +149,6 @@ LIB32_OBJS= \
    "$(INTDIR)\dirmod.obj" \
    "$(INTDIR)\pgsleep.obj" \
    "$(INTDIR)\open.obj" \
-   "$(INTDIR)\syswrap.obj" \
    "$(INTDIR)\win32error.obj" \
    "$(INTDIR)\pthread-win32.obj"
 
@@ -297,11 +295,6 @@ LINK32_FLAGS = -Gn -L$(BCB)\lib;$(INTDIR); -x -Tpd -v
    $(CPP_PROJ) /I"." ..\..\port\open.c
 <<
 
-"$(INTDIR)\syswrap.obj" : ..\..\port\syswrap.c
-   $(CPP) @<<
-   $(CPP_PROJ) ..\..\port\syswrap.c
-<<
-
 "$(INTDIR)\win32error.obj" : ..\..\port\win32error.c
    $(CPP) @<<
    $(CPP_PROJ) /I"." ..\..\port\win32error.c
index 3b703994374d1f521637e85e783e1d788d54ca7b..ee1884fe201125c9ba1b2d260a879596a0efb174 100644 (file)
@@ -113,7 +113,6 @@ CLEAN :
    -@erase "$(INTDIR)\dirmod.obj"
    -@erase "$(INTDIR)\pgsleep.obj"
    -@erase "$(INTDIR)\open.obj"
-   -@erase "$(INTDIR)\syswrap.obj"
    -@erase "$(INTDIR)\win32error.obj"
    -@erase "$(INTDIR)\win32setlocale.obj"
    -@erase "$(OUTDIR)\$(OUTFILENAME).lib"
@@ -160,7 +159,6 @@ LIB32_OBJS= \
    "$(INTDIR)\dirmod.obj" \
    "$(INTDIR)\pgsleep.obj" \
    "$(INTDIR)\open.obj" \
-   "$(INTDIR)\syswrap.obj" \
    "$(INTDIR)\win32error.obj" \
    "$(INTDIR)\win32setlocale.obj" \
    "$(INTDIR)\pthread-win32.obj"
@@ -337,11 +335,6 @@ LINK32_OBJS= \
    $(CPP_PROJ) /I"." ..\..\port\open.c
 <<
 
-"$(INTDIR)\syswrap.obj" : ..\..\port\syswrap.c
-   $(CPP) @<<
-   $(CPP_PROJ) ..\..\port\syswrap.c
-<<
-
 "$(INTDIR)\win32error.obj" : ..\..\port\win32error.c
    $(CPP) @<<
    $(CPP_PROJ) /I"." ..\..\port\win32error.c
index 208d79571bb5ad40153d43771a0d05893507a6a1..c86b47e9d237b9f5a9ec3caa154d3d22dbd2e483 100644 (file)
  * 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,6 +51,7 @@
 #include "XSUB.h"
 
 /* put back our snprintf and vsnprintf */
+#ifdef USE_REPL_SNPRINTF
 #ifdef snprintf
 #undef snprintf
 #endif
 #undef vsnprintf
 #endif
 #ifdef __GNUC__
-#define vsnprintf(...) vsnprintf_throw_on_fail(__VA_ARGS__)
-#define snprintf(...)  snprintf_throw_on_fail(__VA_ARGS__)
+#define vsnprintf(...) pg_vsnprintf(__VA_ARGS__)
+#define snprintf(...)  pg_snprintf(__VA_ARGS__)
 #else
-#define vsnprintf      vsnprintf_throw_on_fail
-#define snprintf       snprintf_throw_on_fail
+#define vsnprintf      pg_vsnprintf
+#define snprintf       pg_snprintf
 #endif   /* __GNUC__ */
+#endif   /* USE_REPL_SNPRINTF */
 
 /* perl version and platform portability */
 #define NEED_eval_pv
index 8f0a27f351f9cdc69b5b421b76a8954dafdf6701..795231c45d33621a233427ce4a3486e14f0a1fc8 100644 (file)
  * So we undefine them here and redefine them after it's done its dirty deed.
  */
 
+#ifdef USE_REPL_SNPRINTF
 #undef snprintf
 #undef vsnprintf
+#endif
 
 #if defined(_MSC_VER) && defined(_DEBUG)
 /* Python uses #pragma to bring in a non-default libpython on VC++ if
@@ -122,6 +124,7 @@ typedef int Py_ssize_t;
 #include <eval.h>
 
 /* put back our snprintf and vsnprintf */
+#ifdef USE_REPL_SNPRINTF
 #ifdef snprintf
 #undef snprintf
 #endif
@@ -129,12 +132,13 @@ typedef int Py_ssize_t;
 #undef vsnprintf
 #endif
 #ifdef __GNUC__
-#define vsnprintf(...) vsnprintf_throw_on_fail(__VA_ARGS__)
-#define snprintf(...)  snprintf_throw_on_fail(__VA_ARGS__)
+#define vsnprintf(...) pg_vsnprintf(__VA_ARGS__)
+#define snprintf(...)  pg_snprintf(__VA_ARGS__)
 #else
-#define vsnprintf      vsnprintf_throw_on_fail
-#define snprintf       snprintf_throw_on_fail
+#define vsnprintf              pg_vsnprintf
+#define snprintf               pg_snprintf
 #endif   /* __GNUC__ */
+#endif   /* USE_REPL_SNPRINTF */
 
 /*
  * Used throughout, and also by the Python 2/3 porting layer, so it's easier to
index ec8651440cc71a7bfa4f940a40178d21a65d2c4f..3a26006b7c1a2031fc374259d5db1b856825ecee 100644 (file)
@@ -33,7 +33,7 @@ LIBS += $(PTHREAD_LIBS)
 OBJS = $(LIBOBJS) chklocale.o dirmod.o erand48.o exec.o fls.o inet_net_ntop.o \
    noblock.o path.o pgcheckdir.o pg_crc.o pgmkdirp.o pgsleep.o \
    pgstrcasecmp.o pqsignal.o \
-   qsort.o qsort_arg.o quotes.o sprompt.o syswrap.o tar.o thread.o \
+   qsort.o qsort_arg.o quotes.o sprompt.o tar.o thread.o \
    wait_error.o
 
 # foo_srv.o and foo.o are both built from foo.c, but only foo.o has -DFRONTEND
index 9dfb57599eeaf1827b570429bd72b9d844c90eaa..ed48bcf44a85b8cb7c5a1faf1c4dd99b068592cf 100644 (file)
@@ -99,7 +99,6 @@
 /* Prevent recursion */
 #undef vsnprintf
 #undef snprintf
-#undef vsprintf
 #undef sprintf
 #undef vfprintf
 #undef fprintf
@@ -176,7 +175,7 @@ pg_snprintf(char *str, size_t count, const char *fmt,...)
    return len;
 }
 
-int
+static int
 pg_vsprintf(char *str, const char *fmt, va_list args)
 {
    PrintfTarget target;
diff --git a/src/port/syswrap.c b/src/port/syswrap.c
deleted file mode 100644 (file)
index 8415a33..0000000
+++ /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;
-}
index 894f9638502302814fe4a98a3a2f0bd2298925ce..3782ec53a231ca2fa25b1f37182d09f29bdb084c 100644 (file)
@@ -70,7 +70,7 @@ sub mkvcbuild
      erand48.c snprintf.c strlcat.c strlcpy.c dirmod.c exec.c noblock.c path.c
      pgcheckdir.c pg_crc.c pgmkdirp.c pgsleep.c pgstrcasecmp.c pqsignal.c
      mkdtemp.c qsort.c qsort_arg.c quotes.c
-     sprompt.c syswrap.c tar.c thread.c wait_error.c getopt.c getopt_long.c dirent.c
+     sprompt.c tar.c thread.c wait_error.c getopt.c getopt_long.c dirent.c
      win32env.c win32error.c win32setlocale.c);
 
    push(@pgportfiles, 'rint.c') if ($vsVersion < '12.00');