]> granicus.if.org Git - php/commitdiff
Use binary safe function for quoting
authorEdin Kadribasic <edink@php.net>
Tue, 25 May 2004 16:24:29 +0000 (16:24 +0000)
committerEdin Kadribasic <edink@php.net>
Tue, 25 May 2004 16:24:29 +0000 (16:24 +0000)
ext/pdo_pgsql/pgsql_driver.c

index 334bf2e016aba521704497e08a075f9051c73597..6d5af4ba378c6b019d2f23820804bfb92a37ccd7 100644 (file)
@@ -136,12 +136,18 @@ static long pgsql_handle_doer(pdo_dbh_t *dbh, const char *sql, long sql_len TSRM
 
 static int pgsql_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, int unquotedlen, char **quoted, int *quotedlen  TSRMLS_DC)
 {
-       *quoted = emalloc(2*unquotedlen + 3);
+       unsigned char *escaped;
+
+       /* escapedlen returned by PQescapeBytea() accounts for trailing 0 */
+       escaped = PQescapeBytea(unquoted, unquotedlen, quotedlen);
+       *quotedlen += 1;
+       *quoted = emalloc(*quotedlen + 1);
+       memcpy((*quoted)+1, escaped, *quotedlen-2);
        (*quoted)[0] = '\'';
-       *quotedlen = PQescapeString(*quoted + 1, unquoted, unquotedlen);
-       (*quoted)[*quotedlen + 1] = '\'';
-       (*quoted)[*quotedlen + 2] = '\0';
-       *quotedlen += 2;
+       (*quoted)[*quotedlen-1] = '\'';
+       (*quoted)[*quotedlen] = '\0';
+       PQfreemem(escaped);
+
        return 1;
 }