1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-21 16:02:15 +03:00
Commit Graph

3421 Commits

Author SHA1 Message Date
9ddda5894c ecpg: Fix off-by-one error in memory copying
In a rare case, one byte past the end of memory belonging to the
sqlca_t structure would be written to.

found by Coverity
2012-03-11 01:03:16 +02:00
b108a77505 ecpg: Fix rare memory leaks
found by Coverity
2012-03-11 01:01:48 +02:00
f054f631a0 Stamp 9.0.7. 2012-02-23 17:56:26 -05:00
850d341ff7 Remove arbitrary limitation on length of common name in SSL certificates.
Both libpq and the backend would truncate a common name extracted from a
certificate at 32 bytes.  Replace that fixed-size buffer with dynamically
allocated string so that there is no hard limit.  While at it, remove the
code for extracting peer_dn, which we weren't using for anything; and
don't bother to store peer_cn longer than we need it in libpq.

This limit was not so terribly unreasonable when the code was written,
because we weren't using the result for anything critical, just logging it.
But now that there are options for checking the common name against the
server host name (in libpq) or using it as the user's name (in the server),
this could result in undesirable failures.  In the worst case it even seems
possible to spoof a server name or user name, if the correct name is
exactly 32 bytes and the attacker can persuade a trusted CA to issue a
certificate in which that string is a prefix of the certificate's common
name.  (To exploit this for a server name, he'd also have to send the
connection astray via phony DNS data or some such.)  The case that this is
a realistic security threat is a bit thin, but nonetheless we'll treat it
as one.

Back-patch to 8.4.  Older releases contain the faulty code, but it's not
a security problem because the common name wasn't used for anything
interesting.

Reported and patched by Heikki Linnakangas

Security: CVE-2012-0867
2012-02-23 15:48:14 -05:00
144fcf754f Translation updates 2012-02-23 20:36:36 +02:00
ebc37d6924 Do not use the variable name when defining a varchar structure in ecpg.
With a unique counter being added anyway, there is no need anymore to have the variable name listed, too.
2012-02-13 15:49:38 +01:00
94c5aa639e fe-misc.c depends on pg_config_paths.h
Declare this in Makefile to avoid failures in parallel compiles.

Author: Lionel Elie Mamane
2012-02-06 11:53:22 -03:00
458a83a526 In ecpg removed old leftover check for given connection name.
Ever since we introduced real prepared statements this should work for
different connections. The old solution just emulating prepared statements,
though, wasn't able to handle this.

Closes: #6309
2011-12-18 18:46:00 +01:00
621fd4d4c0 Applied another patch by Zoltan to fix memory alignement issues in ecpg's sqlda
code.
2011-12-04 04:43:33 +01:00
f3bbd7d814 Treat ENOTDIR as ENOENT when looking for client certificate file
This makes it possible to use a libpq app with home directory set
to /dev/null, for example - treating it the same as if the file
doesn't exist (which it doesn't).

Per bug #6302, reported by Diego Elio Petteno
2011-12-03 15:05:50 +01:00
1c635b03c1 Stamp 9.0.6. 2011-12-01 16:49:59 -05:00
698bb4ec4f Translation updates 2011-12-01 22:59:40 +02:00
acbddf45a4 Applied Zoltan's patch to correctly align interval and timestamp data in ecpg's sqlda. 2011-11-17 14:43:49 +01:00
f72baf7e61 Applied patch by Zoltan to fix copy&paste bug in ecpg's sqlda handling. 2011-11-13 13:48:19 +01:00
8522403c5c Stamp 9.0.5. 2011-09-22 18:00:48 -04:00
b43bb707cc Translation updates 2011-09-22 23:10:16 +03:00
ba24de13f6 Add missing format argument to ecpg_log() call 2011-09-08 22:10:43 +03:00
2cda30e757 Fix brace indentation of commit f8c7442201 to fit PostgreSQL style. 2011-09-02 09:48:19 +02:00
f8c7442201 In ecpglib restore LC_NUMERIC in case of an error. 2011-09-01 15:31:16 +02:00
42de04f6ae Don't assume that "E" response to NEGOTIATE_SSL_CODE means pre-7.0 server.
These days, such a response is far more likely to signify a server-side
problem, such as fork failure.  Reporting "server does not support SSL"
(in sslmode=require) could be quite misleading.  But the results could
be even worse in sslmode=prefer: if the problem was transient and the
next connection attempt succeeds, we'll have silently fallen back to
protocol version 2.0, possibly disabling features the user needs.

Hence, it seems best to just eliminate the assumption that backing off
to non-SSL/2.0 protocol is the way to recover from an "E" response, and
instead treat the server error the same as we would in non-SSL cases.

I tested this change against a pre-7.0 server, and found that there
was a second logic bug in the "prefer" path: the test to decide whether
to make a fallback connection attempt assumed that we must have opened
conn->ssl, which in fact does not happen given an "E" response.  After
fixing that, the code does indeed connect successfully to pre-7.0,
as long as you didn't set sslmode=require.  (If you did, you get
"Unsupported frontend protocol", which isn't completely off base
given the server certainly doesn't support SSL.)

Since there seems no reason to believe that pre-7.0 servers exist anymore
in the wild, back-patch to all supported branches.
2011-08-27 16:37:08 -04:00
431b638045 Ensure we discard unread/unsent data when abandoning a connection attempt.
There are assorted situations wherein PQconnectPoll() will abandon a
connection attempt and try again with different parameters (eg, SSL versus
not SSL).  However, the code forgot to discard any pending data in libpq's
I/O buffers when doing this.  In at least one case (server returns E
message during SSL negotiation), there is unread input data which bollixes
the next connection attempt.  I have not checked to see whether this is
possible in the other cases where we close the socket and retry, but it
seems like a matter of good defensive programming to add explicit
buffer-flushing code to all of them.

This is one of several issues exposed by Daniel Farina's report of
misbehavior after a server-side fork failure.

This has been wrong since forever, so back-patch to all supported branches.
2011-08-27 14:16:25 -04:00
65c033cbe9 Fix previous patch so it also works if not USE_SSL (mea culpa).
On balance, the need to cover this case changes my mind in favor of pushing
all error-message generation duties into the two fe-secure.c routines.
So do it that way.
2011-07-24 23:29:15 -04:00
77e4fd5c4a Improve libpq's error reporting for SSL failures.
In many cases, pqsecure_read/pqsecure_write set up useful error messages,
which were then overwritten with useless ones by their callers.  Fix this
by defining the responsibility to set an error message to be entirely that
of the lower-level function when using SSL.

Back-patch to 8.3; the code is too different in 8.2 to be worth the
trouble.
2011-07-24 16:29:18 -04:00
f0dadcc60b Use OpenSSL's SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER flag.
This disables an entirely unnecessary "sanity check" that causes failures
in nonblocking mode, because OpenSSL complains if we move or compact the
write buffer.  The only actual requirement is that we not modify pending
data once we've attempted to send it, which we don't.  Per testing and
research by Martin Pihlak, though this fix is a lot simpler than his patch.

I put the same change into the backend, although it's less clear whether
it's necessary there.  We do use nonblock mode in some situations in
streaming replication, so seems best to keep the same behavior in the
backend as in libpq.

Back-patch to all supported releases.
2011-07-24 15:18:02 -04:00
fe0e1a633a Fix PQsetvalue() to avoid possible crash when adding a new tuple.
PQsetvalue unnecessarily duplicated the logic in pqAddTuple, and didn't
duplicate it exactly either --- pqAddTuple does not care what is in the
tuple-pointer array positions beyond the last valid entry, whereas the
code in PQsetvalue assumed such positions would contain NULL.  This led
to possible crashes if PQsetvalue was applied to a PGresult that had
previously been enlarged with pqAddTuple, for instance one built from a
server query.  Fix by relying on pqAddTuple instead of duplicating logic,
and not assuming anything about the contents of res->tuples[res->ntups].

Back-patch to 8.4, where PQsetvalue was introduced.

Andrew Chernow
2011-07-21 12:25:01 -04:00
3089a3a101 Adapted expected result for latest change to ecpglib. 2011-07-18 19:03:51 +02:00
77a7a57f7f Made ecpglib write double with a precision of 15 digits.
Patch originally by Akira Kurosawa <kurosawa-akira@mxc.nes.nec.co.jp>.
2011-07-18 16:29:59 +02:00
5246386727 Fix assorted issues with build and install paths containing spaces.
Apparently there is no buildfarm critter exercising this case after all,
because it fails in several places.  With this patch, build, install,
check-world, and installcheck-world pass for me on OS X.
2011-06-14 16:41:23 -04:00
e73bd1e343 Fix portability bugs in use of credentials control messages for peer auth.
Even though our existing code for handling credentials control messages has
been basically unchanged since 2001, it was fundamentally wrong: it did not
ensure proper alignment of the supplied buffer, and it was calculating
buffer sizes and message sizes incorrectly.  This led to failures on
platforms where alignment padding is relevant, for instance FreeBSD on
64-bit platforms, as seen in a recent Debian bug report passed on by
Martin Pitt (http://bugs.debian.org//cgi-bin/bugreport.cgi?bug=612888).

Rewrite to do the message-whacking using the macros specified in RFC 2292,
following a suggestion from Theo de Raadt in that thread.  Tested by me
on Debian/kFreeBSD-amd64; since OpenBSD and NetBSD document the identical
CMSG API, it should work there too.

Back-patch to all supported branches.
2011-05-30 19:16:11 -04:00
30cf86fdf4 Fix write-past-buffer-end in ldapServiceLookup().
The code to assemble ldap_get_values_len's output into a single string
wrote the terminating null one byte past where it should.  Fix that,
and make some other cosmetic adjustments to make the code a trifle more
readable and more in line with usual Postgres coding style.

Also, free the "result" string when done with it, to avoid a permanent
memory leak.

Bug report and patch by Albe Laurenz, cosmetic adjustments by me.
2011-05-12 11:57:05 -04:00
b2e2d3a378 Silence compiler warning about unused variable on Windows. 2011-04-19 14:54:48 +03:00
ffb39e1aed Tag 9.0.4. 2011-04-15 00:15:53 -03:00
65a188e549 Translation updates 2011-04-14 23:29:13 +03:00
0e754ab366 Adjust regression tests on cube and ECPG for MinGW 64 bit compiler.
Backport to 9.0, we're not supporting this compiler on earlier releases.
2011-04-10 17:03:44 -04:00
672def6225 Fix typo in PQconnectStartParams().
This would lead to leaking the PGconn structure after an error detected by
conninfo_array_parse(), as well as failing to return a useful error message
in such cases.  Backpatch to 9.0 where the error was introduced.

Joseph Adams
2011-04-02 18:05:46 -04:00
2f418e8a17 In ecpg preprocessor, don't try to look up constants in the test for
variable hiding. A constant is not a variable. It worked in most cases by
accident, because we add constants to the global list of variables (why?),
but float constants like 1.23 were interpreted as struct field references,
and not found.

Backpatch to 9.0, where the test for variable hiding was added.
2011-03-11 17:23:31 +02:00
2ff092bcd8 In initialize_SSL, don't fail unnecessarily when home dir is unavailable.
Instead, just act as though the certificate file(s) are not present.
There is only one case where this need be a hard failure condition: when
sslmode is verify-ca or verify-full, not having a root cert file is an
error.  Change the logic so that we complain only in that case, and
otherwise fall through cleanly.  This is how it used to behave pre-9.0,
but my patch 4ed4b6c54e of 2010-05-26 broke
the case.  Per report from Christian Kastner.
2011-03-04 11:39:14 -05:00
8e4b147312 Add CheckTableNotInUse calls in DROP TABLE and DROP INDEX.
Recent releases had a check on rel->rd_refcnt in heap_drop_with_catalog,
but failed to cover the possibility of pending trigger events at DROP time.
(Before 8.4 we didn't even check the refcnt.)  When the trigger events were
eventually fired, you'd get "could not open relation with OID nnn" errors,
as in recent report from strk.  Better to throw a suitable error when the
DROP is attempted.

Also add a similar check in DROP INDEX.

Back-patch to all supported branches.
2011-02-15 15:49:59 -05:00
2fb64d8570 Tag 9.0.3 2011-01-27 22:21:31 -04:00
1b2b96c423 In ecpg's parser removed a fixed length limit for constants defining an array dimension. 2011-01-08 23:02:23 +01:00
66b133d2b8 Allow vpath builds and regression tests to succeed on Mingw. Backpatch to release 8.4 - earlier releases would require more changes and it's not worth the trouble. 2010-12-24 13:31:48 -05:00
178ca03f1c Tag 9.0.2. 2010-12-13 22:55:50 -04:00
c8a154e3f8 Translation updates for release 9.0.2 2010-12-13 23:20:00 +02:00
72ba1f2c67 Fix ecpg test building process to not generate *.dSYM junk on Macs.
The trick is to not try to build executables directly from .c files,
but to always build the intermediate .o files.  For obscure reasons,
Darwin's version of gcc will leave debug cruft behind in the first
case but not the second.  Per complaint from Robert Haas.
2010-10-20 00:55:03 -04:00
86d4cc4a2a Applied patch by Itagaki Takahiro to fix incorrect status calculation in
ecpglib. Instead of parsing the statement just as ask the database server.
2010-10-14 17:49:01 +02:00
fd51c16ce9 Tag 9.0.1 2010-10-01 10:28:42 -03:00
4afd557901 Still more .gitignore cleanup.
Fix overly-enthusiastic ignores, as identified by
git ls-files -i --exclude-standard
2010-09-24 13:48:20 -04:00
e482ebdf0b More fixes for libpq's .gitignore file.
The previous patches failed to cover a lot of symlinks that are only
added in platform-specific cases.  Make the lists match what's in the
Makefile for each branch.
2010-09-22 22:32:19 -04:00
f23bc1e8a4 Add gitignore files for ecpg regression tests.
Backpatch to 8.2 as that's how far the structure looks the same.
2010-09-22 21:49:07 +02:00
a692359411 Convert cvsignore to gitignore, and add .gitignore for build targets. 2010-09-22 12:57:06 +02:00