diff options
| author | Noah Misch <noah@leadboat.com> | 2015-05-18 10:02:31 -0400 |
|---|---|---|
| committer | Noah Misch <noah@leadboat.com> | 2015-05-18 10:02:37 -0400 |
| commit | 82b7393eb46482fbfc901a18aaf2d388c2d16d2e (patch) | |
| tree | 86f1e497af6dcf766c47dcdc1da7008fa805ec40 /src/interfaces | |
| parent | 1e6652aea503b16ea99662832d07241bf47f21f3 (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/interfaces')
| -rw-r--r-- | src/interfaces/ecpg/compatlib/Makefile | 1 | ||||
| -rw-r--r-- | src/interfaces/ecpg/ecpglib/.gitignore | 1 | ||||
| -rw-r--r-- | src/interfaces/ecpg/ecpglib/Makefile | 6 | ||||
| -rw-r--r-- | src/interfaces/ecpg/pgtypeslib/.gitignore | 1 | ||||
| -rw-r--r-- | src/interfaces/ecpg/pgtypeslib/Makefile | 6 | ||||
| -rw-r--r-- | src/interfaces/libpq/.gitignore | 1 | ||||
| -rw-r--r-- | src/interfaces/libpq/Makefile | 6 | ||||
| -rw-r--r-- | src/interfaces/libpq/bcc32.mak | 7 | ||||
| -rw-r--r-- | src/interfaces/libpq/win32.mak | 7 |
9 files changed, 27 insertions, 9 deletions
diff --git a/src/interfaces/ecpg/compatlib/Makefile b/src/interfaces/ecpg/compatlib/Makefile index 350ee3d7c84..97c67e9c176 100644 --- a/src/interfaces/ecpg/compatlib/Makefile +++ b/src/interfaces/ecpg/compatlib/Makefile @@ -45,6 +45,7 @@ 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) $< . diff --git a/src/interfaces/ecpg/ecpglib/.gitignore b/src/interfaces/ecpg/ecpglib/.gitignore index 351f43775e8..9d994c160d4 100644 --- a/src/interfaces/ecpg/ecpglib/.gitignore +++ b/src/interfaces/ecpg/ecpglib/.gitignore @@ -5,4 +5,5 @@ /path.c /pgstrcasecmp.c /strlcpy.c +/syswrap.c /thread.c diff --git a/src/interfaces/ecpg/ecpglib/Makefile b/src/interfaces/ecpg/ecpglib/Makefile index 27d1c635f75..51f4f5900c8 100644 --- a/src/interfaces/ecpg/ecpglib/Makefile +++ b/src/interfaces/ecpg/ecpglib/Makefile @@ -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 \ + connect.o misc.o path.o pgstrcasecmp.o syswrap.o \ $(filter snprintf.o strlcpy.o win32setlocale.o isinf.o, $(LIBOBJS)) # thread.c is needed only for non-WIN32 implementation of path.c @@ -57,7 +57,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 thread.c win32setlocale.c isinf.c: % : $(top_srcdir)/src/port/% +path.c pgstrcasecmp.c snprintf.c strlcpy.c syswrap.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 @@ -74,6 +74,6 @@ uninstall: uninstall-lib clean distclean: clean-lib rm -f $(OBJS) - rm -f path.c pgstrcasecmp.c snprintf.c strlcpy.c thread.c win32setlocale.c + rm -f path.c pgstrcasecmp.c snprintf.c strlcpy.c syswrap.c thread.c win32setlocale.c maintainer-clean: distclean maintainer-clean-lib diff --git a/src/interfaces/ecpg/pgtypeslib/.gitignore b/src/interfaces/ecpg/pgtypeslib/.gitignore index 4ee58ea957e..4f97502100e 100644 --- a/src/interfaces/ecpg/pgtypeslib/.gitignore +++ b/src/interfaces/ecpg/pgtypeslib/.gitignore @@ -3,3 +3,4 @@ /exports.list /pgstrcasecmp.c +/syswrap.c diff --git a/src/interfaces/ecpg/pgtypeslib/Makefile b/src/interfaces/ecpg/pgtypeslib/Makefile index 4158b2b666f..3363ee95255 100644 --- a/src/interfaces/ecpg/pgtypeslib/Makefile +++ b/src/interfaces/ecpg/pgtypeslib/Makefile @@ -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 \ + pgstrcasecmp.o syswrap.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: % : $(top_srcdir)/src/port/% +pgstrcasecmp.c rint.c snprintf.c syswrap.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 + rm -f $(OBJS) pgstrcasecmp.c rint.c snprintf.c syswrap.c maintainer-clean: distclean maintainer-clean-lib diff --git a/src/interfaces/libpq/.gitignore b/src/interfaces/libpq/.gitignore index 1784ce11af1..a514b908d0f 100644 --- a/src/interfaces/libpq/.gitignore +++ b/src/interfaces/libpq/.gitignore @@ -11,6 +11,7 @@ /snprintf.c /strerror.c /strlcpy.c +/syswrap.c /thread.c /win32error.c /win32setlocale.c diff --git a/src/interfaces/libpq/Makefile b/src/interfaces/libpq/Makefile index 0d2854946c9..2df4bc4f634 100644 --- a/src/interfaces/libpq/Makefile +++ b/src/interfaces/libpq/Makefile @@ -35,7 +35,7 @@ OBJS= fe-auth.o fe-connect.o fe-exec.o fe-misc.o fe-print.o fe-lobj.o \ fe-protocol2.o fe-protocol3.o pqexpbuffer.o pqsignal.o fe-secure.o \ libpq-events.o # libpgport C files we always use -OBJS += chklocale.o inet_net_ntop.o noblock.o pgstrcasecmp.o thread.o +OBJS += chklocale.o inet_net_ntop.o noblock.o pgstrcasecmp.o syswrap.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 @@ -88,7 +88,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 snprintf.c strerror.c strlcpy.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 snprintf.c strerror.c strlcpy.c syswrap.c thread.c win32error.c win32setlocale.c: % : $(top_srcdir)/src/port/% rm -f $@ && $(LN_S) $< . ip.c md5.c: % : $(backend_src)/libpq/% @@ -149,7 +149,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 thread.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 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 pgsleep.c rm -f md5.c ip.c rm -f encnames.c wchar.c diff --git a/src/interfaces/libpq/bcc32.mak b/src/interfaces/libpq/bcc32.mak index fbef737ecda..25c04f36557 100644 --- a/src/interfaces/libpq/bcc32.mak +++ b/src/interfaces/libpq/bcc32.mak @@ -106,6 +106,7 @@ 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" @@ -149,6 +150,7 @@ LIB32_OBJS= \ "$(INTDIR)\dirmod.obj" \ "$(INTDIR)\pgsleep.obj" \ "$(INTDIR)\open.obj" \ + "$(INTDIR)\syswrap.obj" \ "$(INTDIR)\win32error.obj" \ "$(INTDIR)\pthread-win32.obj" @@ -287,6 +289,11 @@ 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 diff --git a/src/interfaces/libpq/win32.mak b/src/interfaces/libpq/win32.mak index 70a741a5f41..9740f394ea6 100644 --- a/src/interfaces/libpq/win32.mak +++ b/src/interfaces/libpq/win32.mak @@ -113,6 +113,7 @@ 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" @@ -159,6 +160,7 @@ LIB32_OBJS= \ "$(INTDIR)\dirmod.obj" \ "$(INTDIR)\pgsleep.obj" \ "$(INTDIR)\open.obj" \ + "$(INTDIR)\syswrap.obj" \ "$(INTDIR)\win32error.obj" \ "$(INTDIR)\win32setlocale.obj" \ "$(INTDIR)\pthread-win32.obj" @@ -327,6 +329,11 @@ 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 |
