summaryrefslogtreecommitdiff
path: root/ext/pdo_pgsql/pgsql_driver.c
diff options
context:
space:
mode:
authorEdin Kadribasic <edink@php.net>2004-05-25 16:24:29 +0000
committerEdin Kadribasic <edink@php.net>2004-05-25 16:24:29 +0000
commitff1cbb84604fe18592902df4d34e3d6398316f03 (patch)
treea6d7300172c01e3ed8cee3662da0edf095e471bc /ext/pdo_pgsql/pgsql_driver.c
parent737bc357cb3e9d38e1d8b9cfcd3249fd4a79a6e4 (diff)
downloadphp-git-ff1cbb84604fe18592902df4d34e3d6398316f03.tar.gz
Use binary safe function for quoting
Diffstat (limited to 'ext/pdo_pgsql/pgsql_driver.c')
-rw-r--r--ext/pdo_pgsql/pgsql_driver.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/ext/pdo_pgsql/pgsql_driver.c b/ext/pdo_pgsql/pgsql_driver.c
index 334bf2e016..6d5af4ba37 100644
--- a/ext/pdo_pgsql/pgsql_driver.c
+++ b/ext/pdo_pgsql/pgsql_driver.c
@@ -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;
}