pgsql: Modify libpq's string-escaping routines to be aware of encoding

From: tgl(at)postgresql(dot)org (Tom Lane)
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Modify libpq's string-escaping routines to be aware of encoding
Date: 2006-05-21 20:19:44
Message-ID: 20060521201944.6C6689FA19B@postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Log Message:
-----------
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.

Tags:
----
REL8_1_STABLE

Modified Files:
--------------
pgsql/doc/src/sgml:
libpq.sgml (r1.199.2.1 -> r1.199.2.2)
(http://developer.postgresql.org/cvsweb.cgi/pgsql/doc/src/sgml/libpq.sgml.diff?r1=1.199.2.1&r2=1.199.2.2)
pgsql/src/interfaces/libpq:
exports.txt (r1.5 -> r1.5.2.1)
(http://developer.postgresql.org/cvsweb.cgi/pgsql/src/interfaces/libpq/exports.txt.diff?r1=1.5&r2=1.5.2.1)
fe-connect.c (r1.323.2.1 -> r1.323.2.2)
(http://developer.postgresql.org/cvsweb.cgi/pgsql/src/interfaces/libpq/fe-connect.c.diff?r1=1.323.2.1&r2=1.323.2.2)
fe-exec.c (r1.176.2.2 -> r1.176.2.3)
(http://developer.postgresql.org/cvsweb.cgi/pgsql/src/interfaces/libpq/fe-exec.c.diff?r1=1.176.2.2&r2=1.176.2.3)
libpq-fe.h (r1.120.2.1 -> r1.120.2.2)
(http://developer.postgresql.org/cvsweb.cgi/pgsql/src/interfaces/libpq/libpq-fe.h.diff?r1=1.120.2.1&r2=1.120.2.2)
libpq-int.h (r1.108.2.1 -> r1.108.2.2)
(http://developer.postgresql.org/cvsweb.cgi/pgsql/src/interfaces/libpq/libpq-int.h.diff?r1=1.108.2.1&r2=1.108.2.2)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2006-05-21 20:20:05 pgsql: Modify libpq's string-escaping routines to be aware of encoding
Previous Message Tom Lane 2006-05-21 20:19:23 pgsql: Modify libpq's string-escaping routines to be aware of encoding