Skip site navigation (1) Skip section navigation (2)

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:20:05
Message-ID: 20060521202005.297999FA3AD@postgresql.org (view raw or flat)
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_0_STABLE

Modified Files:
--------------
    pgsql/doc/src/sgml:
        libpq.sgml (r1.178.4.2 -> r1.178.4.3)
        (http://developer.postgresql.org/cvsweb.cgi/pgsql/doc/src/sgml/libpq.sgml.diff?r1=1.178.4.2&r2=1.178.4.3)
    pgsql/src/interfaces/libpq:
        exports.txt (r1.3 -> r1.3.4.1)
        (http://developer.postgresql.org/cvsweb.cgi/pgsql/src/interfaces/libpq/exports.txt.diff?r1=1.3&r2=1.3.4.1)
        fe-connect.c (r1.301.4.4 -> r1.301.4.5)
        (http://developer.postgresql.org/cvsweb.cgi/pgsql/src/interfaces/libpq/fe-connect.c.diff?r1=1.301.4.4&r2=1.301.4.5)
        fe-exec.c (r1.166.4.1 -> r1.166.4.2)
        (http://developer.postgresql.org/cvsweb.cgi/pgsql/src/interfaces/libpq/fe-exec.c.diff?r1=1.166.4.1&r2=1.166.4.2)
        libpq-fe.h (r1.116 -> r1.116.4.1)
        (http://developer.postgresql.org/cvsweb.cgi/pgsql/src/interfaces/libpq/libpq-fe.h.diff?r1=1.116&r2=1.116.4.1)
        libpq-int.h (r1.100 -> r1.100.4.1)
        (http://developer.postgresql.org/cvsweb.cgi/pgsql/src/interfaces/libpq/libpq-int.h.diff?r1=1.100&r2=1.100.4.1)

pgsql-committers by date

Next:From: Tom LaneDate: 2006-05-21 20:20:24
Subject: pgsql: Modify libpq's string-escaping routines to be aware of encoding
Previous:From: Tom LaneDate: 2006-05-21 20:19:44
Subject: pgsql: Modify libpq's string-escaping routines to be aware of encoding

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group