summaryrefslogtreecommitdiff
path: root/ext/pgsql/pgsql.c
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2020-09-21 15:46:55 +0200
committerNikita Popov <nikita.ppv@gmail.com>2020-09-21 15:46:55 +0200
commitd1bbc39e4cbf3068ac64e8b107814e0bb8ddc762 (patch)
treeee05af3988e27052eac0d7a3c4706c7cbe045afb /ext/pgsql/pgsql.c
parent5bb41fa63cec0b25470c8202c58f019929dc29a6 (diff)
downloadphp-git-d1bbc39e4cbf3068ac64e8b107814e0bb8ddc762.tar.gz
pg_unescape_bytea() can only fail on OOM
The implementation did not check for PQunescapeBytea failure correctly, because it checked for a null pointer after estrndup, which certainly cannot happen. Inspection of the PGunescapeBytea implementation has shown that this function can only fail on OOM, so let's check for that explicitly and remove false as a possible return type. While we're here, avoid an unnecessary copy of the result.
Diffstat (limited to 'ext/pgsql/pgsql.c')
-rw-r--r--ext/pgsql/pgsql.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c
index 31bb834314..0112bcc7b6 100644
--- a/ext/pgsql/pgsql.c
+++ b/ext/pgsql/pgsql.c
@@ -3362,7 +3362,7 @@ PHP_FUNCTION(pg_escape_bytea)
/* {{{ Unescape binary for bytea type */
PHP_FUNCTION(pg_unescape_bytea)
{
- char *from = NULL, *to = NULL, *tmp = NULL;
+ char *from, *tmp;
size_t to_len;
size_t from_len;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s!",
@@ -3371,14 +3371,13 @@ PHP_FUNCTION(pg_unescape_bytea)
}
tmp = (char *)PQunescapeBytea((unsigned char*)from, &to_len);
- to = estrndup(tmp, to_len);
- PQfreemem(tmp);
- if (!to) {
- php_error_docref(NULL, E_WARNING,"Invalid parameter");
- RETURN_FALSE;
+ if (!tmp) {
+ zend_error(E_ERROR, "Out of memory");
+ return;
}
- RETVAL_STRINGL(to, to_len);
- efree(to);
+
+ RETVAL_STRINGL(tmp, to_len);
+ PQfreemem(tmp);
}
/* }}} */