Skip to content

Commit 0e6d6f8

Browse files
committed
Fix GH-8253: pg_insert() fails for references
We need to deref the values. Closes GH-8262.
1 parent fe4aba6 commit 0e6d6f8

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ PHP NEWS
2727

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

3132
- Sockets:
3233
. Fixed Solaris builds. (David Carlier)

ext/pgsql/pgsql.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4595,6 +4595,7 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con
45954595

45964596
ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(values), field, val) {
45974597
skip_field = 0;
4598+
ZVAL_DEREF(val);
45984599
ZVAL_NULL(&new_val);
45994600

46004601
/* TODO: Check when meta data can be broken and see if can use assertions instead */

ext/pgsql/tests/gh8253.phpt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--TEST--
2+
pg_insert() fails for references
3+
--SKIPIF--
4+
<?php
5+
include("skipif.inc");
6+
?>
7+
--FILE--
8+
<?php
9+
include "config.inc";
10+
11+
function fee(&$a) {}
12+
$a = ["bar" => "testing"];
13+
fee($a["bar"]);
14+
15+
$db = pg_connect($conn_str);
16+
pg_query($db, "DROP TABLE IF EXISTS gh8253");
17+
pg_query($db, "CREATE TABLE gh8253 (bar text);");
18+
pg_insert($db, "gh8253", $a);
19+
$res = pg_query($db, "SELECT * FROM gh8253");
20+
var_dump(pg_fetch_all($res));
21+
?>
22+
--EXPECT--
23+
array(1) {
24+
[0]=>
25+
array(1) {
26+
["bar"]=>
27+
string(7) "testing"
28+
}
29+
}

0 commit comments

Comments
 (0)