14499 Commits

Author SHA1 Message Date
Tom Lane
e6f43f7786 Modify libpq's string-escaping routines to be aware of encoding considerations
and standard_conforming_strings.  The encoding changes are needed for proper
escaping in multibyte encodings, as per the SQL-injection vulnerabilities
noted in CVE-2006-2313 and CVE-2006-2314.  Concurrent fixes are being applied
to the server to ensure that it rejects queries that may have been corrupted
by attempted SQL injection, but this merely guarantees that unpatched clients
will fail rather than allow injection.  An actual fix requires changing the
client-side code.  While at it we have also fixed these routines to understand
about standard_conforming_strings, so that the upcoming changeover to SQL-spec
string syntax can be somewhat transparent to client code.

Since the existing API of PQescapeString and PQescapeBytea provides no way to
inform them which settings are in use, these functions are now deprecated in
favor of new functions PQescapeStringConn and PQescapeByteaConn.  The new
functions take the PGconn to which the string will be sent as an additional
parameter, and look inside the connection structure to determine what to do.
So as to provide some functionality for clients using the old functions,
libpq stores the latest encoding and standard_conforming_strings values
received from the backend in static variables, and the old functions consult
these variables.  This will work reliably in clients using only one Postgres
connection at a time, or even multiple connections if they all use the same
encoding and string syntax settings; which should cover many practical
scenarios.

Clients that use homebrew escaping methods, such as PHP's addslashes()
function or even hardwired regexp substitution, will require extra effort
to fix :-(.  It is strongly recommended that such code be replaced by use of
PQescapeStringConn/PQescapeByteaConn if at all feasible.
2006-05-21 20:20:48 +00:00
Tom Lane
16e77740ea Add a new GUC parameter backslash_quote, which determines whether the SQL
parser will allow "\'" to be used to represent a literal quote mark.  The
"\'" representation has been deprecated for some time in favor of the
SQL-standard representation "''" (two single quote marks), but it has been
used often enough that just disallowing it immediately won't do.  Hence
backslash_quote allows the settings "on", "off", and "safe_encoding",
the last meaning to allow "\'" only if client_encoding is a valid server
encoding.  That is now the default, and the reason is that in encodings
such as SJIS that allow 0x5c (ASCII backslash) to be the last byte of a
multibyte character, accepting "\'" allows SQL-injection attacks as per
CVE-2006-2314 (further details will be published after release).  The
"on" setting is available for backward compatibility, but it must not be
used with clients that are exposed to untrusted input.

Thanks to Akio Ishida and Yasuo Ohgaki for identifying this security issue.
2006-05-21 20:12:20 +00:00
Tom Lane
5c4de67044 Change the backend to reject strings containing invalidly-encoded multibyte
characters in all cases.  Formerly we mostly just threw warnings for invalid
input, and failed to detect it at all if no encoding conversion was required.
The tighter check is needed to defend against SQL-injection attacks as per
CVE-2006-2313 (further details will be published after release).  Embedded
zero (null) bytes will be rejected as well.  The checks are applied during
input to the backend (receipt from client or COPY IN), so it no longer seems
necessary to check in textin() and related routines; any string arriving at
those functions will already have been validated.  Conversion failure
reporting (for characters with no equivalent in the destination encoding)
has been cleaned up and made consistent while at it.

Also, fix a few longstanding errors in little-used encoding conversion
routines: win1251_to_iso, win866_to_iso, euc_tw_to_big5, euc_tw_to_mic,
mic_to_euc_tw were all broken to varying extents.

Patches by Tatsuo Ishii and Tom Lane.  Thanks to Akio Ishida and Yasuo Ohgaki
for identifying the security issues.
2006-05-21 20:07:13 +00:00
Bruce Momjian
583a472f7b Change \' to '', for SQL standards compliance. Backpatch to 7.3, 7.4,
and 8.0.  Later releases already patched.
2006-05-21 19:56:41 +00:00
Tom Lane
506747337b Fix the sense of the test on DH_check()'s return value. This was preventing
custom-generated DH parameters from actually being used by the server.
Found by Michael Fuhr.
2006-05-12 22:45:06 +00:00
Tom Lane
76dc24091f Remove unnecessary .seg/.section directives, per Alan Stange. 2006-05-11 22:00:12 +00:00
Tom Lane
803d61a353 Fix ancient memory leak in PQprintTuples(); our code no longer uses this
routine, but perhaps some applications do.  Found by Martijn van Oosterhout
using Coverity.
2006-04-19 16:16:08 +00:00
Tatsuo Ishii
342fae3dc5 Minor teak. 2006-03-04 12:35:08 +00:00
Tatsuo Ishii
52c4e32d5f Tighten up SJIS byte sequence check. Now we reject invalid SJIS byte
sequence such as "0x95 0x27". Patches from Akio Ishida.
2006-03-04 12:32:59 +00:00
Neil Conway
11b3472672 Fix three Python reference leaks in PLy_traceback(). This would result
in leaking memory when invoking a PL/Python procedure that raises an
exception. Unfortunately this still leaks memory, but at least the
largest leak has been plugged.

This patch also fixes a reference counting mistake in PLy_modify_tuple()
for 8.0, 8.1 and HEAD: we don't actually own a reference to `platt', so
we shouldn't Py_DECREF() it.
2006-02-20 20:10:48 +00:00
Neil Conway
0c853662bd Patch from Marko Kreen:
pgcrypto crypt()/md5 and hmac() leak memory when compiled against
OpenSSL as openssl.c digest ->reset will do two DigestInit calls
against a context.  This happened to work with OpenSSL 0.9.6
but not with 0.9.7+.

Reason for the messy code was that I tried to avoid creating
wrapper structure to transport algorithm info and tried to use
OpenSSL context for it.  The fix is to create wrapper structure.

It also uses newer digest API to avoid memory allocations
on reset with newer OpenSSLs.

Thanks to Daniel Blaisdell for reporting it.
2006-02-18 20:49:02 +00:00
Tom Lane
eb46ad568d Stamp 7.3.14. REL7_3_14 2006-02-12 22:38:54 +00:00
Tom Lane
ee7c1a3fd4 Update release notes. 2006-02-12 22:36:16 +00:00
Tom Lane
118f54d06d Fix bug in SET SESSION AUTHORIZATION that allows unprivileged users to crash
the server, if it has been compiled with Asserts enabled (CVE-2006-0553).
Thanks to Akio Ishida for reporting this problem.
2006-02-12 22:33:47 +00:00
Bruce Momjian
da91fde3e8 Update FAQ latest version 2006-02-12 18:50:07 +00:00
Bruce Momjian
c551fd362e Stamp releases for 2006-02-14 release 2006-02-12 18:41:22 +00:00
Bruce Momjian
db4534e31f Update release notes for 2006-02-14 release 2006-02-12 18:23:00 +00:00
Tom Lane
3cbc8b6fb4 Repair longstanding bug in slru/clog logic: it is possible for two backends
to try to create a log segment file concurrently, but the code erroneously
specified O_EXCL to open(), resulting in a needless failure.  Before 7.4,
it was even a PANIC condition :-(.  Correct code is actually simpler than
what we had, because we can just say O_CREAT to start with and not need a
second open() call.  I believe this accounts for several recent reports of
hard-to-reproduce "could not create file ...: File exists" errors in both
pg_clog and pg_subtrans.
2006-01-21 04:38:54 +00:00
Tom Lane
a6cc7db9a6 Repair "Halloween problem" in EvalPlanQual: a tuple that's been inserted by
our own command (or more generally, xmin = our xact and cmin >= current
command ID) should not be seen as good.  Else we may try to update rows
we already updated.  This error was inserted last August while fixing the
even bigger problem that the old coding wouldn't see *any* tuples inserted
by our own transaction as good.  Per report from Euler Taveira de Oliveira.
2006-01-12 21:49:41 +00:00
Tom Lane
158c7f32b4 Use a more bulletproof test for whether finite() and isinf() are present.
It seems that recent gcc versions can optimize away calls to these functions
even when the functions do not exist on the platform, resulting in a bogus
positive result.  Avoid this by using a non-constant argument and ensuring
that the function result is not simply discarded.  Per report from
François Laupretre.
2006-01-12 19:24:48 +00:00
Tom Lane
b4feb29e0d Fix pg_dump to add the required OPERATOR() decoration to schema-qualified
operator names.  This is needed when dumping operator definitions that have
COMMUTATOR (or similar) links to operators in other schemas.
Apparently Daniel Whitter is the first person ever to try this :-(
2006-01-09 21:16:57 +00:00
Tom Lane
88f2145326 Fix failure to apply domain constraints to a NULL constant that's added to
an INSERT target list during rule rewriting.  Per report from John Supplee.
2006-01-06 20:11:36 +00:00
Tom Lane
751c4818bf Release-note updates and copy editing. REL7_3_13 2006-01-06 03:00:46 +00:00
Tom Lane
d3e91bd475 Generate back-branch configure scripts with the appropriate version of autoconf. 2006-01-06 02:31:25 +00:00
Bruce Momjian
a93eb7cef2 New pgcrypto item wording. 2006-01-05 15:17:08 +00:00
Bruce Momjian
e6e13b5da9 Wording improvements. 2006-01-05 15:11:07 +00:00
Bruce Momjian
7251950412 Improve markup. 2006-01-05 14:52:40 +00:00
Bruce Momjian
00214b611c *** empty log message *** 2006-01-05 05:21:40 +00:00
Bruce Momjian
44a3ad2ab0 Stamp release 7.3.13. 2006-01-05 03:59:21 +00:00
Tom Lane
040d3e63a7 Arrange to set the LC_XXX environment variables to match our locale setup.
Back-patch of previous fix in HEAD for plperl-vs-locale issue.
2006-01-05 00:55:36 +00:00
Tom Lane
3abc36786b Add port support for unsetenv() in back branches. Needed for locale
environment fix.
2006-01-05 00:51:52 +00:00
Joe Conway
4e0f51f13d When the remote query result has a different number of columns
than the local query specifies (e.g. in the FROM clause),
throw an ERROR (instead of crashing). Fix for bug #2129 reported
by Akio Iwaasa.
2006-01-03 23:48:42 +00:00
Tom Lane
a74dc12416 There is a signedness bug in Openwall gen_salt code that pgcrypto uses.
This makes the salt space for md5 and xdes algorithms a lot smaller than
it should be.

Marko Kreen
2006-01-03 23:46:56 +00:00
Tatsuo Ishii
951f2bdd23 Fix long standing Asian multibyte charsets bug.
See:

Subject: [HACKERS] bugs with certain Asian multibyte charsets
From: Tatsuo Ishii <ishii@sraoss.co.jp>
To: pgsql-hackers@postgresql.org
Date: Sat, 24 Dec 2005 18:25:33 +0900 (JST)

for more details.
2005-12-24 12:08:10 +00:00
Tom Lane
cd726e1cf8 Adjust string comparison so that only bitwise-equal strings are considered
equal: if strcoll claims two strings are equal, check it with strcmp, and
sort according to strcmp if not identical.  This fixes inconsistent
behavior under glibc's hu_HU locale, and probably under some other locales
as well.  Also, take advantage of the now-well-defined behavior to speed up
texteq, textne, bpchareq, bpcharne: they may as well just do a bitwise
comparison and not bother with strcoll at all.

NOTE: affected databases may need to REINDEX indexes on text columns to be
sure they are self-consistent.
2005-12-22 22:50:29 +00:00
Tom Lane
660fcf0f67 Back-patch 7.4 change to show that freebsd 5 and up don't need
float8-small-is-zero.  Per Mark Kirkwood.
2005-12-15 05:43:35 +00:00
Tom Lane
93bcee8d4e Remove unused HAVE_STRUCT_SOCKCRED code, which was causing a duplicate-
variable-definition error on recent FreeBSDen (evidently, that platform
also HAS_STRUCT_CMSGCRED).  Backport of 7.4 fix dated 2003-10-25.
2005-12-13 03:36:14 +00:00
Tom Lane
fbb687fa1b Stamp 7.3.12. REL7_3_12 2005-12-09 20:56:45 +00:00
Tom Lane
52d70a3088 Add release notes for back branches (7.3 and up).
Also minor improvements to 8.1.1 release notes.
2005-12-09 20:41:11 +00:00
Teodor Sigaev
85fc9ad4af Fix stupid bug with sizeof 2005-12-06 18:22:09 +00:00
Tom Lane
304b231e7b Add regression test to see if the min/max values of int8 convert correctly. 2005-12-05 04:14:39 +00:00
Bruce Momjian
62b91ec937 Properly document return value of strpos(). 2005-11-16 03:58:08 +00:00
Tom Lane
237afd453f Fix longstanding race condition in transaction log management: there was a
very narrow window in which SimpleLruReadPage or SimpleLruWritePage could
think that I/O was needed when it wasn't (and indeed the buffer had already
been assigned to another page).  This would result in an Assert failure if
Asserts were enabled, and probably in silent data corruption if not.
Reported independently by Jim Nasby and Robert Creager.

I intend a more extensive fix when 8.2 development starts, but this is a
reasonably low-impact patch for the existing branches.
2005-11-03 00:23:57 +00:00
Tom Lane
aaaacf0f6c Fix longstanding bug that would sometimes let the planner generate a bad plan
for an outer join; symptom is bogus error "RIGHT JOIN is only supported with
merge-joinable join conditions".  Problem was that select_mergejoin_clauses
did its tests in the wrong order.  We need to force left join not right join
for a merge join when there are non-mergeable join clauses; but the test for
this only accounted for mergejoinability of the clause operator, and not
whether the left and right Vars were of the proper relations.  Per report
from Jean-Pierre Pelletier.
2005-10-25 20:30:52 +00:00
Tom Lane
0fa322a14e Pass a strdup'd ident string to openlog(), to ensure that reallocation
of GUC memory doesn't cause us to start emitting a bogus ident string.
Per report from Han Holl.  Also some trivial code cleanup in write_syslog.
2005-10-14 16:41:41 +00:00
Tom Lane
10f14e6e0d Fix longstanding bug found by Atsushi Ogawa: _bt_check_unique would mark
the wrong buffer dirty when trying to kill a dead index entry that's on
a page after the one it started on.  No risk of data corruption, just
inefficiency, but still a bug.
2005-10-12 17:18:45 +00:00
Tom Lane
ae049f191d Stamp release 7.3.11. REL7_3_11 2005-10-03 17:24:27 +00:00
Tom Lane
69fbf4816b Update release notes for pending back-branch releases. 2005-10-03 16:05:29 +00:00
Teodor Sigaev
ba5f900b3d Fix missing rows in query
update a=.. where a... with GiST index on column 'a'
Backpatch from 8.0 branch
2005-08-30 08:48:16 +00:00
Tom Lane
26f1202ca3 Back-patch fixes for problems with VACUUM destroying t_ctid chains too soon,
and with insufficient paranoia in code that follows t_ctid links.
This patch covers the 7.3 branch.
2005-08-26 20:07:17 +00:00