Commit graph

3526 commits

Author SHA1 Message Date
Michael Meskes
994362a317 Return error if allocation of new element was not possible.
Found by Coverity.
2013-09-08 13:13:22 +02:00
Michael Meskes
aef9d25aa3 Close file to no leak file descriptor memory. Found by Coverity. 2013-09-08 13:13:22 +02:00
Peter Eisentraut
a2e66c03a4 libpq: Report strerror on pthread_mutex_lock() failure 2013-08-17 21:52:35 -04:00
Stephen Frost
71127756af Improve handling of pthread_mutex_lock error case
We should really be reporting a useful error along with returning
a valid return code if pthread_mutex_lock() throws an error for
some reason.  Add that and back-patch to 9.0 as the prior patch.

Pointed out by Alvaro Herrera
2013-08-01 15:43:46 -04:00
Stephen Frost
0b821b8d7c Add locking around SSL_context usage in libpq
I've been working with Nick Phillips on an issue he ran into when
trying to use threads with SSL client certificates.  As it turns out,
the call in initialize_SSL() to SSL_CTX_use_certificate_chain_file()
will modify our SSL_context without any protection from other threads
also calling that function or being at some other point and trying to
read from SSL_context.

To protect against this, I've written up the attached (based on an
initial patch from Nick and much subsequent discussion) which puts
locks around SSL_CTX_use_certificate_chain_file() and all of the other
users of SSL_context which weren't already protected.

Nick Phillips, much reworked by Stephen Frost

Back-patch to 9.0 where we started loading the cert directly instead of
using a callback.
2013-08-01 01:24:01 -04:00
Alvaro Herrera
15fdf7302a Check for NULL result from strdup
Per Coverity Scan
2013-07-23 17:38:31 -04:00
Michael Meskes
4652abeb30 Initialize day of year value.
There are cases where the day of year value in struct tm is used, but it never
got calculated. Problem found by Coverity scan.
2013-07-19 09:05:18 +02:00
Michael Meskes
6dc4e62d04 Also escape double quotes for ECPG's #line statement. 2013-07-06 22:12:14 +02:00
Michael Meskes
2bb2a29c71 Applied patch by MauMau <maumau307@gmail.com> to escape filenames in #line statements. 2013-07-05 11:15:19 +02:00
Tom Lane
c204aba26c Expect EWOULDBLOCK from a non-blocking connect() call only on Windows.
On Unix-ish platforms, EWOULDBLOCK may be the same as EAGAIN, which is
*not* a success return, at least not on Linux.  We need to treat it as a
failure to avoid giving a misleading error message.  Per the Single Unix
Spec, only EINPROGRESS and EINTR returns indicate that the connection
attempt is in progress.

On Windows, on the other hand, EWOULDBLOCK (WSAEWOULDBLOCK) is the expected
case.  We must accept EINPROGRESS as well because Cygwin will return that,
and it doesn't seem worth distinguishing Cygwin from native Windows here.
It's not very clear whether EINTR can occur on Windows, but let's leave
that part of the logic alone in the absence of concrete trouble reports.

Also, remove the test for errno == 0, effectively reverting commit
da9501bddb, which AFAICS was just a thinko;
or at best it might have been a workaround for a platform-specific bug,
which we can hope is gone now thirteen years later.  In any case, since
libpq makes no effort to reset errno to zero before calling connect(),
it seems unlikely that that test has ever reliably done anything useful.

Andres Freund and Tom Lane
2013-06-27 12:37:20 -04:00
Tom Lane
114fca526e Stamp 9.1.9. 2013-04-01 14:23:05 -04:00
Peter Eisentraut
54d4a8f023 Translation updates 2013-03-31 23:40:34 -04:00
Alvaro Herrera
861aac5870 Translation updates 2013-03-31 16:41:13 -03:00
Tom Lane
3a77936602 Fix overflow check in tm2timestamp (this time for sure).
I fixed this code back in commit 841b4a2d5, but didn't think carefully
enough about the behavior near zero, which meant it improperly rejected
1999-12-31 24:00:00.  Per report from Magnus Hagander.
2013-03-04 15:14:00 -05:00
Tom Lane
69c026512f Stamp 9.1.8. 2013-02-04 16:28:27 -05:00
Peter Eisentraut
390523596d Translation updates 2013-02-03 23:58:38 -05:00
Michael Meskes
f1a4b15871 Made ecpglib use translated messages.
Bug reported and fixed by Chen Huajun <chenhj@cn.fujitsu.com>.
2013-01-27 13:50:28 +01:00
Tom Lane
2e892a15b9 Fix one-byte buffer overrun in PQprintTuples().
This bug goes back to the original Postgres95 sources.  Its significance
to modern PG versions is marginal, since we have not used PQprintTuples()
internally in a very long time, and it doesn't seem to have ever been
documented either.  Still, it *is* exposed to client apps, so somebody
out there might possibly be using it.

Xi Wang
2013-01-20 23:43:56 -05:00
Michael Meskes
93c041ab10 Include isinf.o in libecpg if isinf() is not available on the system.
Patch done by Jiang Guiqing <jianggq@cn.fujitsu.com>.
2012-12-04 16:41:15 +01:00
Tom Lane
c47f643c49 Stamp 9.1.7. 2012-12-03 15:19:35 -05:00
Peter Eisentraut
04a210b090 Translation updates 2012-12-03 07:53:51 -05:00
Tom Lane
c6a91c92b5 Produce a more useful error message for over-length Unix socket paths.
The length of a socket path name is constrained by the size of struct
sockaddr_un, and there's not a lot we can do about it since that is a
kernel API.  However, it would be a good thing if we produced an
intelligible error message when the user specifies a socket path that's too
long --- and getaddrinfo's standard API is too impoverished to do this in
the natural way.  So insert explicit tests at the places where we construct
a socket path name.  Now you'll get an error that makes sense and even
tells you what the limit is, rather than something generic like
"Non-recoverable failure in name resolution".

Per trouble report from Jeremy Drake and a fix idea from Andrew Dunstan.
2012-11-29 19:57:17 -05:00
Michael Meskes
381c3b8f4c When processing nested structure pointer variables ecpg always expected an
array datatype which of course is wrong.

Applied patch by Muhammad Usama <m.usama@gmail.com> to fix this.
2012-11-29 17:15:02 +01:00
Tom Lane
bb3aa7a484 Fix lo_import and lo_export to return useful error messages more often.
I found that these functions tend to return -1 while leaving an empty error
message string in the PGconn, if they suffer some kind of I/O error on the
file.  The reason is that lo_close, which thinks it's executed a perfectly
fine SQL command, clears the errorMessage.  The minimum-change workaround
is to reorder operations here so that we don't fill the errorMessage until
after lo_close.
2012-10-08 21:52:48 -04:00
Michael Meskes
856ce0fb56 Fixed test for array boundary.
Instead of continuing if the next character is not an array boundary get_data()
used to continue only on finding a boundary so it was not able to read any
element after the first.
2012-10-05 17:06:44 +02:00
Tom Lane
04a37a5716 Stamp 9.1.6. 2012-09-19 17:50:31 -04:00
Tom Lane
1e214507e5 Use .NOTPARALLEL in ecpg/Makefile to avoid a gmake parallelism bug.
Investigation shows that some intermittent build failures in ecpg are the
result of a gmake bug that was reported quite some time ago:
http://savannah.gnu.org/bugs/?30653

Preventing parallel builds of the ecpg subdirectories seems to dodge the
bug.  Per yesterday's pgsql-hackers discussion, there are some other things
in the subdirectory makefiles that seem rather unsafe for parallel builds
too, but there's little point in fixing them as long as we have to work
around a make bug.

Back-patch to 9.1; parallel builds weren't very well supported before
that anyway.
2012-09-09 15:09:11 -04:00
Tom Lane
04e96bc69d Stamp 9.1.5. 2012-08-14 18:41:04 -04:00
Peter Eisentraut
b5987c4f87 Translation updates 2012-08-14 16:34:12 -04:00
Peter Eisentraut
e23e17ffb0 Update copyright year in forgotten places
found by Stefan Kaltenbrunner
2012-06-19 21:36:08 +03:00
Tom Lane
8e61ded616 Stamp 9.1.4. 2012-05-31 19:07:09 -04:00
Peter Eisentraut
8620f6f18e Translation updates 2012-05-31 23:31:41 +03:00
Peter Eisentraut
3043608cf7 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:09 +02:00
Peter Eisentraut
6f59d42b94 ecpg: Fix rare memory leaks
found by Coverity
2012-03-11 01:01:22 +02:00
Peter Eisentraut
0ba7ff5fa5 libpq: Fix memory leak
If a client encoding is specified as a connection parameter (or
environment variable), internal storage allocated for it would never
be freed.
2012-03-11 00:47:36 +02:00
Tom Lane
64c47e4542 Stamp 9.1.3. 2012-02-23 17:53:36 -05:00
Tom Lane
e6fcb03dc0 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:09 -05:00
Peter Eisentraut
602dd1eeaa Translation updates 2012-02-23 20:40:55 +02:00
Michael Meskes
421513ba84 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:48:49 +01:00
Alvaro Herrera
2a84671909 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:52:01 -03:00
Michael Meskes
bb4cfebd64 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:45:39 +01:00
Michael Meskes
7c9557b6f8 Applied another patch by Zoltan to fix memory alignement issues in ecpg's sqlda
code.
2011-12-04 04:43:09 +01:00
Magnus Hagander
a6f8e7d959 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:35 +01:00
Tom Lane
cfd8cf37d2 Stamp 9.1.2. 2011-12-01 16:47:20 -05:00
Peter Eisentraut
a03c47c29e Translation updates 2011-12-01 23:03:05 +02:00
Michael Meskes
165fd3947a Applied Zoltan's patch to correctly align interval and timestamp data in ecpg's sqlda. 2011-11-17 14:12:00 +01:00
Michael Meskes
8fad10a575 Applied patch by Zoltan to fix copy&paste bug in ecpg's sqlda handling. 2011-11-13 13:52:40 +01:00
Tom Lane
8da4007a4d Stamp 9.1.1. 2011-09-22 17:57:57 -04:00
Peter Eisentraut
f992679318 Translation updates 2011-09-22 23:24:25 +03:00
Heikki Linnakangas
f6950429da 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:59:25 +03:00