diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2020-09-21 15:46:55 +0200 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2020-09-21 15:46:55 +0200 |
commit | d1bbc39e4cbf3068ac64e8b107814e0bb8ddc762 (patch) | |
tree | ee05af3988e27052eac0d7a3c4706c7cbe045afb /ext/pgsql | |
parent | 5bb41fa63cec0b25470c8202c58f019929dc29a6 (diff) | |
download | php-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')
-rw-r--r-- | ext/pgsql/pgsql.c | 15 | ||||
-rw-r--r-- | ext/pgsql/pgsql.stub.php | 2 | ||||
-rw-r--r-- | ext/pgsql/pgsql_arginfo.h | 4 |
3 files changed, 10 insertions, 11 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); } /* }}} */ diff --git a/ext/pgsql/pgsql.stub.php b/ext/pgsql/pgsql.stub.php index e5e5300056..181d62c9cd 100644 --- a/ext/pgsql/pgsql.stub.php +++ b/ext/pgsql/pgsql.stub.php @@ -425,7 +425,7 @@ function pg_escape_string($connection, string $data = UNKNOWN): string {} /** @param resource|string $connection */ function pg_escape_bytea($connection, string $data = UNKNOWN): string {} -function pg_unescape_bytea(?string $data = null): string|false {} +function pg_unescape_bytea(?string $data = null): string {} /** @param resource|string $connection */ function pg_escape_literal($connection, string $data = UNKNOWN): string|false {} diff --git a/ext/pgsql/pgsql_arginfo.h b/ext/pgsql/pgsql_arginfo.h index a6adbb7582..c2b2387154 100644 --- a/ext/pgsql/pgsql_arginfo.h +++ b/ext/pgsql/pgsql_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: e5f2c8b3b23876a05a48500f626e81549e5d2ab1 */ + * Stub hash: 87152e947ab7bfb3a9d7df30dd6fbccac504504e */ ZEND_BEGIN_ARG_INFO_EX(arginfo_pg_connect, 0, 0, 1) ZEND_ARG_TYPE_INFO(0, connection_string, IS_STRING, 0) @@ -325,7 +325,7 @@ ZEND_END_ARG_INFO() #define arginfo_pg_escape_bytea arginfo_pg_escape_string -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_pg_unescape_bytea, 0, 0, MAY_BE_STRING|MAY_BE_FALSE) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_pg_unescape_bytea, 0, 0, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, data, IS_STRING, 1, "null") ZEND_END_ARG_INFO() |