mirror of
https://github.com/postgres/postgres.git
synced 2025-07-30 11:03:19 +03:00
I've attached the fixed version of the patch below. After the
discussion on pgsql-hackers (especially the frightening memory dump in <12273.999562219@sss.pgh.pa.us>), we decided that it is best not to use identifiers from an untrusted source at all. Therefore, all claims of the suitability of PQescapeString() for identifiers have been removed. Florian Weimer
This commit is contained in:
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.109 2001/09/06 02:54:56 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.110 2001/09/07 22:02:32 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -56,6 +56,62 @@ static int getAnotherTuple(PGconn *conn, int binary);
|
||||
static int getNotify(PGconn *conn);
|
||||
static int getNotice(PGconn *conn);
|
||||
|
||||
/* ---------------
|
||||
* Escaping arbitrary strings to get valid SQL strings/identifiers.
|
||||
*
|
||||
* Replaces "\\" with "\\\\", "\0" with "\\0", and "'" with "''".
|
||||
* length is the length of the buffer pointed to by
|
||||
* from. The buffer at to must be at least 2*length + 1 characters
|
||||
* long. A terminating NUL character is written.
|
||||
* ---------------
|
||||
*/
|
||||
|
||||
size_t
|
||||
PQescapeString (char *to, const char *from, size_t length)
|
||||
{
|
||||
const char *source = from;
|
||||
char *target = to;
|
||||
unsigned int remaining = length;
|
||||
|
||||
while (remaining > 0) {
|
||||
switch (*source) {
|
||||
case '\0':
|
||||
*target = '\\';
|
||||
target++;
|
||||
*target = '0';
|
||||
/* target and remaining are updated below. */
|
||||
break;
|
||||
|
||||
case '\\':
|
||||
*target = '\\';
|
||||
target++;
|
||||
*target = '\\';
|
||||
/* target and remaining are updated below. */
|
||||
break;
|
||||
|
||||
case '\'':
|
||||
*target = '\'';
|
||||
target++;
|
||||
*target = '\'';
|
||||
/* target and remaining are updated below. */
|
||||
break;
|
||||
|
||||
default:
|
||||
*target = *source;
|
||||
/* target and remaining are updated below. */
|
||||
}
|
||||
source++;
|
||||
target++;
|
||||
remaining--;
|
||||
}
|
||||
|
||||
/* Write the terminating NUL character. */
|
||||
*target = '\0';
|
||||
|
||||
return target - to;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* ----------------
|
||||
* Space management for PGresult.
|
||||
|
Reference in New Issue
Block a user