From 74caae4934ecde1f4061436e9960f7571ca364b7 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Mon, 28 Mar 2022 14:37:22 +0200 Subject: [PATCH] Fix GH-8253: pg_insert() fails for references We need to deref the values. --- ext/pgsql/pgsql.c | 1 + ext/pgsql/tests/gh8253.phpt | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 ext/pgsql/tests/gh8253.phpt diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c index 70a78643fa54a..64bce7dda4017 100644 --- a/ext/pgsql/pgsql.c +++ b/ext/pgsql/pgsql.c @@ -4595,6 +4595,7 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(values), field, val) { skip_field = 0; + ZVAL_DEREF(val); ZVAL_NULL(&new_val); /* TODO: Check when meta data can be broken and see if can use assertions instead */ diff --git a/ext/pgsql/tests/gh8253.phpt b/ext/pgsql/tests/gh8253.phpt new file mode 100644 index 0000000000000..24a4b96295837 --- /dev/null +++ b/ext/pgsql/tests/gh8253.phpt @@ -0,0 +1,29 @@ +--TEST-- +pg_insert() fails for references +--SKIPIF-- + +--FILE-- + "testing"]; +fee($a["bar"]); + +$db = pg_connect($conn_str); +pg_query($db, "DROP TABLE IF EXISTS gh8253"); +pg_query($db, "CREATE TABLE gh8253 (bar text);"); +pg_insert($db, "gh8253", $a); +$res = pg_query($db, "SELECT * FROM gh8253"); +var_dump(pg_fetch_all($res)); +?> +--EXPECT-- +array(1) { + [0]=> + array(1) { + ["bar"]=> + string(7) "testing" + } +}