Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 54549d8

Browse files
committed
> I found a problem with PQescapeString (I think). Since it escapes
> null bytes to be literally '\0', the following can happen: > 1. User inputs string value as "<null byte>##" where ## are digits in the > range of 0 to 7. > 2. PQescapeString converts this to "\0##" > 3. Escaped string is used in a context that causes "\0##" to be evaluated as > an octal escape sequence. I agree that this is a problem, though it is not possible to do anything harmful with it. In addition, it only occurs if there are any NUL characters in its input, which is very unlikely if you are using C strings. The patch below addresses the issue by removing escaping of \0 characters entirely. > If the goal is to "safely" encode null bytes, and preserve the rest of the > string as it was entered, I think the null bytes should be escaped as \\000 > (note that if you simply use \000 the same string truncation problem > occurs). We can't do that, this would require 4n + 1 bytes of storage for the result, breaking the interface. Florian Weimer
1 parent 351a0c1 commit 54549d8

File tree

2 files changed

+3
-10
lines changed

2 files changed

+3
-10
lines changed

src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1396,7 +1396,7 @@ public static boolean toBoolean(String s)
13961396
if (s != null)
13971397
{
13981398
int c = s.charAt(0);
1399-
return ((c == 't') || (c == 'T'));
1399+
return ((c == 't') || (c == 'T') || (c == '1'));
14001400
}
14011401
return false; // SQL NULL
14021402
}

src/interfaces/libpq/fe-exec.c

+2-9
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.110 2001/09/07 22:02:32 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.111 2001/09/13 17:00:34 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -59,7 +59,7 @@ static int getNotice(PGconn *conn);
5959
/* ---------------
6060
* Escaping arbitrary strings to get valid SQL strings/identifiers.
6161
*
62-
* Replaces "\\" with "\\\\", "\0" with "\\0", and "'" with "''".
62+
* Replaces "\\" with "\\\\" and "'" with "''".
6363
* length is the length of the buffer pointed to by
6464
* from. The buffer at to must be at least 2*length + 1 characters
6565
* long. A terminating NUL character is written.
@@ -75,13 +75,6 @@ PQescapeString (char *to, const char *from, size_t length)
7575

7676
while (remaining > 0) {
7777
switch (*source) {
78-
case '\0':
79-
*target = '\\';
80-
target++;
81-
*target = '0';
82-
/* target and remaining are updated below. */
83-
break;
84-
8578
case '\\':
8679
*target = '\\';
8780
target++;

0 commit comments

Comments
 (0)