Skip to content

Commit

Permalink
Fix GH-8253: pg_insert() fails for references
Browse files Browse the repository at this point in the history
We need to deref the values.

Closes GH-8262.
  • Loading branch information
cmb69 committed Mar 29, 2022
1 parent fe4aba6 commit 0e6d6f8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ PHP NEWS

- PgSQL:
. Fixed result_type related stack corruption on LLP64 architectures. (cmb)
. Fixed bug GH-8253 (pg_insert() fails for references). (cmb)

- Sockets:
. Fixed Solaris builds. (David Carlier)
Expand Down
1 change: 1 addition & 0 deletions ext/pgsql/pgsql.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
29 changes: 29 additions & 0 deletions ext/pgsql/tests/gh8253.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
--TEST--
pg_insert() fails for references
--SKIPIF--
<?php
include("skipif.inc");
?>
--FILE--
<?php
include "config.inc";

function fee(&$a) {}
$a = ["bar" => "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"
}
}

0 comments on commit 0e6d6f8

Please sign in to comment.