Commit Graph

3460 Commits

Author SHA1 Message Date
8269e4091c Translation updates 2013-12-02 00:05:18 -05:00
ddd8416e40 ECPG: Fix offset to NULL/size indicator array.
Patch by Boszormenyi Zoltan <zb@cybertec.at>
2013-11-26 17:31:45 +01:00
7bee2e3e55 ECPG: Make the preprocessor emit ';' if the variable type for a list of
variables is varchar. This fixes this test case:

int main(void)
{
    exec sql begin declare section;
    varchar a[50], b[50];
    exec sql end declare section;

    return 0;
}

Since varchars are internally turned into custom structs and
the type name is emitted for these variable declarations,
the preprocessed code previously had:

struct varchar_1  { ... }  a _,_  struct varchar_2  { ... }  b ;

The comma in the generated C file was a syntax error.

There are no regression test changes since it's not exercised.

Patch by Boszormenyi Zoltan <zb@cybertec.at>

Conflicts:
	src/interfaces/ecpg/preproc/ecpg.trailer
2013-11-26 17:31:39 +01:00
da174fb039 Changed test case slightly so it doesn't have an unused typedef. 2013-11-03 16:18:10 +01:00
a65e6c8217 Stamp 9.0.14. 2013-10-07 23:12:23 -04:00
676f3d2e5a Translation updates 2013-10-07 16:12:32 -04:00
1ba5fe8dd4 Fix SSL deadlock risk in libpq
In libpq, we set up and pass to OpenSSL callback routines to handle
locking.  When we run out of SSL connections, we try to clean things
up by de-registering the hooks.  Unfortunately, we had a few calls
into the OpenSSL library after these hooks were de-registered during
SSL cleanup which lead to deadlocking.  This moves the thread callback
cleanup to be after all SSL-cleanup related OpenSSL library calls.
I've been unable to reproduce the deadlock with this fix.

In passing, also move the close_SSL call to be after unlocking our
ssl_config mutex when in a failure state.  While it looks pretty
unlikely to be an issue, it could have resulted in deadlocks if we
ended up in this code path due to something other than SSL_new
failing.  Thanks to Heikki for pointing this out.

Back-patch to all supported versions; note that the close_SSL issue
only goes back to 9.0, so that hunk isn't included in the 8.4 patch.

Initially found and reported by Vesa-Matti J Kari; many thanks to
both Heikki and Andres for their help running down the specific
issue and reviewing the patch.
2013-09-23 08:43:15 -04:00
994f68d15b Return error if allocation of new element was not possible.
Found by Coverity.
2013-09-08 13:13:32 +02:00
3f092dbedf Close file to no leak file descriptor memory. Found by Coverity. 2013-09-08 13:13:32 +02:00
8e0b7d2219 libpq: Report strerror on pthread_mutex_lock() failure 2013-08-17 21:55:15 -04:00
f019c02111 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:49 -04:00
f310163655 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:05 -04:00
f6a6d204fd Check for NULL result from strdup
Per Coverity Scan
2013-07-23 17:38:31 -04:00
ffb28554c3 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:01 +02:00
6b51f659c0 Also escape double quotes for ECPG's #line statement. 2013-07-06 22:12:32 +02:00
d0d7125239 Applied patch by MauMau <maumau307@gmail.com> to escape filenames in #line statements. 2013-07-05 11:15:30 +02:00
a5380bd65b 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
da9501bddb42222dc33c031b1db6ce2133bcee7b, 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:34 -04:00
a941e89a38 Stamp 9.0.13. 2013-04-01 14:25:34 -04:00
315af69420 Translation updates 2013-03-31 23:38:50 -04:00
aab4cbfafb Translation updates 2013-03-31 16:40:25 -03:00
da5f032a83 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:13 -05:00
3da04a0bb1 Stamp 9.0.12. 2013-02-04 16:28:41 -05:00
8e2469a02d Translation updates 2013-02-03 23:56:29 -05:00
2dde6751a0 Made ecpglib use translated messages.
Bug reported and fixed by Chen Huajun <chenhj@cn.fujitsu.com>.
2013-01-27 13:50:54 +01:00
e4cfb5f2e6 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:44:01 -05:00
2e375ab4b5 Fix Makefile breakage caused by a committed merge conflict. 2012-12-04 12:23:36 -05:00
f928ffd65e 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:43:59 +01:00
6fa51d4ba7 Stamp 9.0.11. 2012-12-03 15:22:30 -05:00
f14bd22a52 Translation updates 2012-12-03 07:52:39 -05:00
31c341ae13 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:24 -05:00
3dfdf28152 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:15 +01:00
875406af6f 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:53 -04:00
6b0d71bf71 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:05:53 +02:00
22cdae947b Stamp 9.0.10. 2012-09-19 17:53:08 -04:00
3b849dbf41 Stamp 9.0.9. 2012-08-14 18:43:20 -04:00
1bfe3d602b Translation updates 2012-08-14 16:32:19 -04:00
10a376c772 Update copyright year in forgotten places
found by Stefan Kaltenbrunner
2012-06-19 21:35:35 +03:00
eab246d75f Stamp 9.0.8. 2012-05-31 19:09:35 -04:00
7c61eb3fa6 Translation updates 2012-05-31 23:27:32 +03:00
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