From 18c4bb8dc95c72c9f0b4f2e889f6525a4afbeb31 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Fri, 19 Jul 2024 23:11:17 +0100 Subject: [PATCH] ext/pgsql: db metadata simplification for table names. --- ext/pgsql/pgsql.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c index 5f83f539438b3..ce68fd8e642e9 100644 --- a/ext/pgsql/pgsql.c +++ b/ext/pgsql/pgsql.c @@ -4442,7 +4442,7 @@ PHP_PGSQL_API zend_result php_pgsql_meta_data(PGconn *pg_link, const zend_string char *src, *tmp_name, *tmp_name2 = NULL; char *escaped; smart_str querystr = {0}; - size_t new_len; + size_t new_len, len; int i, num_rows; zval elem; @@ -4480,16 +4480,18 @@ PHP_PGSQL_API zend_result php_pgsql_meta_data(PGconn *pg_link, const zend_string " JOIN pg_namespace n ON (c.relnamespace = n.oid) " "WHERE a.attnum > 0 AND c.relname = '"); } - escaped = (char *)safe_emalloc(strlen(tmp_name2), 2, 1); - new_len = PQescapeStringConn(pg_link, escaped, tmp_name2, strlen(tmp_name2), NULL); + len = strlen(tmp_name2); + escaped = (char *)safe_emalloc(len, 2, 1); + new_len = PQescapeStringConn(pg_link, escaped, tmp_name2, len, NULL); if (new_len) { smart_str_appendl(&querystr, escaped, new_len); } efree(escaped); smart_str_appends(&querystr, "' AND n.nspname = '"); - escaped = (char *)safe_emalloc(strlen(tmp_name), 2, 1); - new_len = PQescapeStringConn(pg_link, escaped, tmp_name, strlen(tmp_name), NULL); + len = strlen(tmp_name); + escaped = (char *)safe_emalloc(len, 2, 1); + new_len = PQescapeStringConn(pg_link, escaped, tmp_name, len, NULL); if (new_len) { smart_str_appendl(&querystr, escaped, new_len); }