Commit Graph

70 Commits

Author SHA1 Message Date
Tom Lane cd9b4f24ce Remove extraneous leading whitespace in Windows build script.
Apparently, at least some versions of Microsoft's shell fail on variable
assignments that have leading whitespace.  This instance, introduced in
commit 680513ab7, managed to escape notice for awhile because it's only
invoked if building with OpenSSL.  Per bug #14185 from Torben Dannhauer.

Report: <20160613140119.5798.78501@wrigleys.postgresql.org>
2016-06-13 11:50:27 -04:00
Tom Lane e7bcde8ca0 Remove unnecessary definition of _WIN64 in libpq/win32.mak.
In commit b0e40d1893, I should have just
removed the /D switch defining WIN64.  The reason the code worked before
is that all Windows64 compilers automatically predefine _WIN64.  Perhaps
at one time we had code that depended on WIN64 being defined, but it's
long gone, and we should not encourage any reappearance.  Per discussion
with Christian Ullrich.
2016-04-12 10:52:58 -04:00
Tom Lane b0e40d1893 Fix two places that thought Windows64 is indicated by WIN64 macro.
Everyplace else thinks it's _WIN64, so make these places fall in line.

The pg_regress.c usage is not going to result in any change in behavior,
only suppressing (or not) a compiler warning about downcasting HANDLEs.
So there seems no need for back-patching there.

The libpq/win32.mak usage might represent an actual bug, if anyone were
using this script to build for Windows64, which perhaps nobody is.
Given the lack of field complaints, no back-patch here either.

pg_regress.c problem found by Christian Ullrich, the other by me.
2016-04-11 19:37:04 -04:00
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
Noah Misch 53566fc094 MinGW: Link with shell32.dll instead of shfolder.dll.
This improves consistency with the MSVC build.  On buildfarm member
narwhal, since commit 846e91e022,
shfolder.dll:SHGetFolderPath() crashes when dblink calls it by way of
pqGetHomeDirectory().  Back-patch to 9.4, where that commit first
appeared.  How it caused this regression remains a mystery.  This is a
partial revert of commit 889f038129, which
adopted shfolder.dll for Windows NT 4.0 compatibility.  PostgreSQL 8.2
dropped support for that operating system.
2014-10-21 22:55:43 -04:00
Heikki Linnakangas 680513ab79 Break out OpenSSL-specific code to separate files.
This refactoring is in preparation for adding support for other SSL
implementations, with no user-visible effects. There are now two #defines,
USE_OPENSSL which is defined when building with OpenSSL, and USE_SSL which
is defined when building with any SSL implementation. Currently, OpenSSL is
the only implementation so the two #defines go together, but USE_SSL is
supposed to be used for implementation-independent code.

The libpq SSL code is changed to use a custom BIO, which does all the raw
I/O, like we've been doing in the backend for a long time. That makes it
possible to use MSG_NOSIGNAL to block SIGPIPE when using SSL, which avoids
a couple of syscall for each send(). Probably doesn't make much performance
difference in practice - the SSL encryption is expensive enough to mask the
effect - but it was a natural result of this refactoring.

Based on a patch by Martijn van Oosterhout from 2006. Briefly reviewed by
Alvaro Herrera, Andreas Karlsson, Jeff Janes.
2014-08-11 11:54:19 +03:00
Magnus Hagander a16bac36ec Remove dependency on wsock32.lib in favor of ws2_32
ws2_32 is the new version of the library that should be used, as
it contains the require functionality from wsock32 as well as some
more (which is why some binaries were already using ws2_32).

Michael Paquier, reviewed by MauMau
2014-07-15 14:18:39 +02: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
Heikki Linnakangas 09e98a3e17 Teach the makefile used to build stand-alone libpq on Windows that libpq
needs win32setlocale.c now. The cygwin and MSVC build scripts were changed
earlier, but this was neglected. This should fix bug report #6203 by Steve.
2011-09-14 17:57:32 +03: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
Magnus Hagander fe4b8c42ad Add missing library to standalone libpq build on Win32.
Hiroshi Saito
2009-11-23 12:54:37 +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
Magnus Hagander f6c1dece9a Fix standalone libpq build on win32.
Hiroshi Saito
2008-06-27 18:58:14 +00:00
Magnus Hagander e3109ba159 Add more dependencies from libpgport required by
standalone msvc build of libpq.

Hiroshi Saito
2008-05-05 19:31:40 +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
Magnus Hagander 21a00dc6fd Generate and include manifest in standalone libpq build on Windows.
Hiroshi Saito
2008-01-10 16:03:00 +00:00
Magnus Hagander de1172fa06 Default to thread safety on, and support more CPU options. Also
make sure that a CPU option is actually chosen.

Hiroshi Saito
2007-10-02 19:01:45 +00:00
Magnus Hagander b8ce3d3494 Build with /GS on 64-bit to work with modern Platform SDK.
Hiroshi Saito
2007-10-01 14:32:02 +00:00
Magnus Hagander 3f0245cb24 Update supported standalone VC++ version to 7.1+ only, and fix
some bad data leftover in win32.mak.

Per request from Hiroshi Saito.
2007-08-03 10:47:11 +00:00
Magnus Hagander 5cbb11928e Fix standalone win32 makefile (MSVC6) for SSPI and GSSAPI.
Hiroshi Saito
2007-07-25 11:37:25 +00:00
Magnus Hagander 432ea3cffd Enable building of 64-bit libpq using visual studio 8 and the
win32.mak file.
Enable building with kerberos support using the win32.mak file.

Hiroshi Saito + me
2007-04-18 13:50:09 +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
Bruce Momjian ed95aea27d MSVC/BCC Win32 compiler fixes.
Hiroshi Saito
2006-10-10 21:31:44 +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 8a7a6afe2d Suppress MSVC warnings about weak functions by using
_CRT_SECURE_NO_DEPRECATE.

Hiroshi Saito
2006-08-09 03:09:56 +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 399a36a75d Prepare code to be built by MSVC:
o  remove many WIN32_CLIENT_ONLY defines
	o  add WIN32_ONLY_COMPILER define
	o  add 3rd argument to open() for portability
	o  add include/port/win32_msvc directory for
	   system includes

Magnus Hagander
2006-06-07 22:24:46 +00:00
Bruce Momjian eab3e9b80d This correction is required of nmake of Windows.
Hiroshi Saito
2005-09-16 18:58:48 +00:00
Bruce Momjian 624789d191 Cleanup for Win32 compile.
Andreas Pflug
2005-06-19 13:10:56 +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 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
Tom Lane 889f038129 Use SHGetFolderPath instead of SHGetSpecialFolderPath to find the
APPDATA directory on Windows.  Magnus Hagander
2005-01-26 19:24:03 +00:00
Tom Lane 8e4f4078d8 Un-break MSVC build, per Andrew Dunstan. 2005-01-10 00:19:51 +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 af70d57825 Enable thread safety for win32.mak build of PostgreSQL.
Andreas Pflug
2004-06-19 04:22:17 +00:00
Bruce Momjian af44cac6ef The attached patch will create a dummy pg_config_paths.h. Additionally,
ENABLE_THREAD_SAFETY is supported by the makefile (but not by the
sources, which need some rework)

Andreas Pflug
2004-06-04 13:30:04 +00:00
Bruce Momjian 1881c8f3c5 Add new Win32 file with adjustments for recent code changes.
Andreas Pflug
2004-06-03 00:11:13 +00:00
Bruce Momjian 422d4819ee Corrects issues recently posted by Dann Corbit, allowing libpq/psql to
be built under VC++. Moves a pgstat win32 #def to port.h

Claudio Natoli
2004-04-05 03:16:21 +00:00
Bruce Momjian 53cd7cd8a9 Make a separate win32 debug DLL along with the non-debug version:
Currently, src/interfaces/libpq/win32.mak builds a statically-linked
library "libpq.lib", a debug dll "libpq.dll", import library for the
debug dll "libpqdll.lib", a release dll "libpq.dll", import library for
the release dll "libpqdll.lib".  To avoid naming clashes, I would make
the debug dll and import libraries "libpqd.dll" and "libpqddll.lib".

Basically, the debug build uses the cl flags: "/MDd /D _DEBUG", and the
release build uses the cl flags "/MD /D NDEBUG".  Usually the debug
build has a "D" suffix on the file name, so for example:

libpqd.dll     libpq, debug build
libpqd.lib     libpq, debug build, import library
libpq.dll      libpq, release build
libpq.lib      libpq, release build, import library

David Turner
2004-03-09 04:53:37 +00:00