summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoe Conway <mail@joeconway.com>2003-11-30 20:55:09 +0000
committerJoe Conway <mail@joeconway.com>2003-11-30 20:55:09 +0000
commitb8f40ced2f7daebb13a3c9ab9aece5a969e2c28a (patch)
tree2535bd3b45be19b38f6212e42dd71c92396dfbe6 /src
parent32abf0e781d813a5ceca77928997fff434a06a8f (diff)
Make PQescapeBytea and byteaout consistent with each other, and
octal escape all octets outside the range 0x20 to 0x7e. This fixes the problem pointed out by Sergey Yatskevich here: http://archives.postgresql.org/pgsql-bugs/2003-11/msg00140.php
Diffstat (limited to 'src')
-rw-r--r--src/backend/utils/adt/varlena.c14
-rw-r--r--src/interfaces/libpq/fe-exec.c9
2 files changed, 12 insertions, 11 deletions
diff --git a/src/backend/utils/adt/varlena.c b/src/backend/utils/adt/varlena.c
index 244e2fbc698..8e01f9f539e 100644
--- a/src/backend/utils/adt/varlena.c
+++ b/src/backend/utils/adt/varlena.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/varlena.c,v 1.107 2003/11/29 19:51:59 pgsql Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/varlena.c,v 1.108 2003/11/30 20:55:09 joe Exp $
*
*-------------------------------------------------------------------------
*/
@@ -186,10 +186,10 @@ byteaout(PG_FUNCTION_ARGS)
{
if (*vp == '\\')
len += 2;
- else if (isprint((unsigned char) *vp))
- len++;
- else
+ else if ((unsigned char) *vp < 0x20 || (unsigned char) *vp > 0x7e)
len += 4;
+ else
+ len++;
}
rp = result = (char *) palloc(len);
vp = VARDATA(vlena);
@@ -200,9 +200,7 @@ byteaout(PG_FUNCTION_ARGS)
*rp++ = '\\';
*rp++ = '\\';
}
- else if (isprint((unsigned char) *vp))
- *rp++ = *vp;
- else
+ else if ((unsigned char) *vp < 0x20 || (unsigned char) *vp > 0x7e)
{
val = *vp;
rp[0] = '\\';
@@ -213,6 +211,8 @@ byteaout(PG_FUNCTION_ARGS)
rp[1] = DIG(val & 03);
rp += 4;
}
+ else
+ *rp++ = *vp;
}
*rp = '\0';
PG_RETURN_CSTRING(result);
diff --git a/src/interfaces/libpq/fe-exec.c b/src/interfaces/libpq/fe-exec.c
index 19cb840af71..84b7d2e1c19 100644
--- a/src/interfaces/libpq/fe-exec.c
+++ b/src/interfaces/libpq/fe-exec.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/interfaces/libpq/fe-exec.c,v 1.154 2003/11/29 19:52:11 pgsql Exp $
+ * $PostgreSQL: pgsql/src/interfaces/libpq/fe-exec.c,v 1.155 2003/11/30 20:55:09 joe Exp $
*
*-------------------------------------------------------------------------
*/
@@ -2261,7 +2261,8 @@ PQescapeString(char *to, const char *from, size_t length)
* '\0' == ASCII 0 == \\000
* '\'' == ASCII 39 == \'
* '\\' == ASCII 92 == \\\\
- * anything >= 0x80 ---> \\ooo (where ooo is an octal expression)
+ * anything < 0x20, or > 0x7e ---> \\ooo
+ * (where ooo is an octal expression)
*/
unsigned char *
PQescapeBytea(const unsigned char *bintext, size_t binlen, size_t *bytealen)
@@ -2280,7 +2281,7 @@ PQescapeBytea(const unsigned char *bintext, size_t binlen, size_t *bytealen)
vp = bintext;
for (i = binlen; i > 0; i--, vp++)
{
- if (*vp == 0 || *vp >= 0x80)
+ if (*vp < 0x20 || *vp > 0x7e)
len += 5; /* '5' is for '\\ooo' */
else if (*vp == '\'')
len += 2;
@@ -2299,7 +2300,7 @@ PQescapeBytea(const unsigned char *bintext, size_t binlen, size_t *bytealen)
for (i = binlen; i > 0; i--, vp++)
{
- if (*vp == 0 || *vp >= 0x80)
+ if (*vp < 0x20 || *vp > 0x7e)
{
(void) sprintf(rp, "\\\\%03o", *vp);
rp += 5;