Commit Graph

40 Commits

Author SHA1 Message Date
Tom Lane 0c071936e9 Revert error-throwing wrappers for the printf family of functions.
This reverts commit 16304a0134, except
for its changes in src/port/snprintf.c; as well as commit
cac18a76bb 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
2015-05-19 18:19:38 -04:00
Noah Misch 16304a0134 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
2015-05-18 10:02:31 -04:00
Heikki Linnakangas a692ee5870 Replace SYSTEMQUOTEs with Windows-specific wrapper functions.
It's easy to forget using SYSTEMQUOTEs when constructing command strings
for system() or popen(). Even if we fix all the places missing it now, it is
bound to be forgotten again in the future. Introduce wrapper functions that
do the the extra quoting for you, and get rid of SYSTEMQUOTEs in all the
callers.

We previosly used SYSTEMQUOTEs in all the hard-coded command strings, and
this doesn't change the behavior of those. But user-supplied commands, like
archive_command, restore_command, COPY TO/FROM PROGRAM calls, as well as
pgbench's \shell, will now gain an extra pair of quotes. That is desirable,
but if you have existing scripts or config files that include an extra
pair of quotes, those might need to be adjusted.

Reviewed by Amit Kapila and Tom Lane
2014-05-05 16:07:40 +03:00
Tom Lane b1fae823ee Re-include pqsignal() in libpq.
We need this in non-ENABLE_THREAD_SAFETY builds, and also to satisfy
the exports.txt entry; while it might be a good idea to remove the
latter, I'm hesitant to do so except in the context of an intentional
ABI break.  At least we don't have a separately maintained source file
for it anymore.
2013-03-17 15:45:31 -04:00
Tom Lane da5aeccf64 Move pqsignal() to libpgport.
We had two copies of this function in the backend and libpq, which was
already pretty bogus, but it turns out that we need it in some other
programs that don't use libpq (such as pg_test_fsync).  So put it where
it probably should have been all along.  The signal-mask-initialization
support in src/backend/libpq/pqsignal.c stays where it is, though, since
we only need that in the backend.
2013-03-17 12:06:42 -04:00
Tom Lane 95d035e66d Autoconfiscate selection of 64-bit int type for 64-bit large object API.
Get rid of the fundamentally indefensible assumption that "long long int"
exists and is exactly 64 bits wide on every platform Postgres runs on.
Instead let the configure script select the type to use for "pg_int64".

This is a bit of a pain in the rear since we do not want to pollute client
namespace with all the random symbols that pg_config.h defines; instead
we have to create a separate generated header file, "pg_config_ext.h".
But now that the infrastructure is there, we might have the ability to
add some other stuff that's long been wanting in this area.
2012-10-07 21:52:43 -04:00
Bruce Momjian 7b8e10f2be Allow bcc32 and win32 batch files to compile libpq.
Backpatch to 9.1.

By Hiroshi Saito
2011-09-07 15:43:50 -04:00
Peter Eisentraut fc946c39ae Remove useless whitespace at end of lines 2010-11-23 22:34:55 +02:00
Tom Lane ce53791b2a Assorted portability fixes for Borland C, from Pavel Golub. 2009-04-19 22:37:13 +00:00
Magnus Hagander b1eeeb20d9 Update standalong libpq makefiles for msvc and bcc to work with the new
libpq events code.

Hiroshi Saito
2008-10-27 09:10:04 +00:00
Bruce Momjian 1883b988d5 Synchronize Borland libpq makefile to match MSVC. Backpatch to 8.3.X. 2008-08-16 01:56:20 +00:00
Peter Eisentraut 0e04ee41d0 Create two separate libpq.rc's: One that is built at build time, and one
that is shipped in the distribution, named libpq-dist.rc.  This way the
build system doesn't get upset when a distributed file is forcibly
overwritten by during a normal build.
2008-02-26 13:31:40 +00:00
Bruce Momjian d65b42b85b Fix build of libpq for Borland CC. 2007-11-21 23:03:44 +00:00
Magnus Hagander c0aa50630b Remove unsafe calling of WSAStartup and WSACleanup from DllMain. Move the
inline cleanup call around so it will be called in the right order, and
be called on errors.

Per report from Tokuharu Yuzawa.
2007-03-08 19:27:28 +00:00
Bruce Momjian a5ec2ec77a Allow Borland CC to compile libpq and psql.
Backpatch to 8.2.X.

L Bayuk
2007-01-11 02:42:31 +00:00
Tom Lane 617f123f06 Get rid of retail definitions of HAVE_STRDUP and HAVE_VSNPRINTF in
some of the Windows-only makefiles; the correct place to assert these
things is pg_config.h.win32.  Per bug #2677.
2006-11-21 23:26:47 +00:00
Tom Lane 85bbd549d8 Oops, forgot that libpq needs extra steps to make use of src/port/ files. 2006-09-27 21:29:17 +00:00
Bruce Momjian 97c3fcd9b7 Move pthread-win32.h to /port, modify bcc/msvc makefiles. 2006-07-10 18:53:29 +00:00
Bruce Momjian ed3b2e696b Have BCC echo output "" using "", rather than \"\" as earlier reported.
Backpatch to 8.1.X.
2006-06-06 16:17:20 +00:00
Bruce Momjian a16ffee73b Fixes for BCC 5.5 compile of libpq. Backpatch to 8.1.X.
Mark Morgan Lloyd
2006-04-24 04:03:25 +00:00
Bruce Momjian 1d734b79a3 Adjust bcc to work for thread changes. 2005-09-16 19:00:05 +00:00
Bruce Momjian ba90268e2b Add comment about \# in bcc makefiles. 2005-06-19 13:14:20 +00:00
Bruce Momjian 16d4418bf5 Fix BCC to not define compiler location. 2005-04-30 04:00:07 +00:00
Bruce Momjian 930dd70992 Improve cleanup from win32 client-only build. 2005-04-29 14:07:27 +00:00
Bruce Momjian 7cebfdf211 Backpatch BCC compile changes to 8.0.X for psql. 2005-04-29 13:42:21 +00:00
Bruce Momjian 61b640e35c Properly implement "Response files" for bcc. Add URL's to describe the
feature for Win32 and bcc.
2005-03-07 21:10:58 +00:00
Bruce Momjian c5a7a6a3dc Tab indent all actions in bcc32.mak, and do it on win32.mak too for
consistency.  Backpatch only bcc32.mak to 8.0.X.
2005-02-27 22:39:52 +00:00
Bruce Momjian 33b92a78da Add linking from /port to bcc makefile. 2005-02-25 15:57:33 +00:00
Bruce Momjian 1808ce7865 Try to get Borland CC to compile.
Backpatch to 8.0.X which doesn't work right now.
2005-02-21 21:22:32 +00:00
Bruce Momjian 1c5125adf3 Not entirely sure when this broke, but libpq's VC++ build is currently
lacking pqsignal which is now required. This was found and fixed for
VC++ by Shachar Shemesh, I simply duplicated the fix for the Borland
makefile (untested, as I don't have that compiler).

Dave Page
2004-11-13 03:18:50 +00:00
Tom Lane cc6a90e4af Remove dllist.c from libpq. It's overkill for what libpq needs; we can
just stick a list-link into struct PGnotify instead.  Result is a smaller
faster and more robust library (mainly because we reduce the number of
malloc's and free's involved in notify processing), plus less pollution
of application link-symbol namespace.
2004-10-16 22:52:55 +00:00
Bruce Momjian 8cef6ae522 Remove pg_config_paths.h from libpq *.mak builds so later MinGW builds
will succeed.
2004-09-02 02:02:02 +00:00
Bruce Momjian 4fa8b44749 Realign libpq and psql for need for path.c under Win32 VC and BCC. 2004-09-01 23:35:16 +00:00
Bruce Momjian d2b7f511da >OK, if you look at the last few commits to interfaces/libpq/win32.mak,
>you will see changes for pg_config_paths.h and for thread safety.  Can
>you look at those changes, merge them into bcc.mak.  There might be
>other changes in there you want to add to bcc.mak too.
>
>
>
OK, having no M$ diff, I attach files src\interfaces\libpq\bcc32.mak and
src\interfaces\libpq\win32.h

Steve Holdoway
2004-07-31 06:19:23 +00:00
Bruce Momjian 38887379a2 Reorder win32/bcc makefile mentions of thread.c for sanity. 2003-11-30 06:01:15 +00:00
Bruce Momjian edfccd3d32 Add thread.c to Borland CC build. 2003-11-30 05:54:33 +00:00
Bruce Momjian b14295cfe4 Attached is the complete diff against current CVS.
Compiles on BCC 5.5 and VC++ 6.0 (with warnings).

Karl Waclawek
2003-06-12 08:15:29 +00:00
Bruce Momjian dc4ee8a833 Back out patch that got bundled into another patch. 2003-06-12 08:11:07 +00:00
Bruce Momjian a647e30ba3 New patch with corrected README attached.
Also quickly added mention that it may be a qualified schema name.

Rod Taylor
2003-06-12 08:02:57 +00:00
Bruce Momjian d82794ee33 Attached is a patch to provide makefiles, etc. to allow the compilation
of the libpq interface static and dynamic libraries with the freely
downloadable Borland C++ compiler version 5.5 and/or C++ Builder.

Lester Godwin
2002-12-30 21:07:26 +00:00