From 2610149500fcc6e7d229c4978c0941664d8a04ca Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Thu, 23 Feb 2023 05:35:39 +0000 Subject: [PATCH 1/2] Fix GH-10672 (pg_lo_open segfaults in the strict_types mode) We need to use the proper ZPP qualifier for zend_string --- ext/pgsql/pgsql.c | 2 +- ext/pgsql/tests/gh10672.phpt | 43 ++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 ext/pgsql/tests/gh10672.phpt diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c index 4422e4259a532..a0c83fd955abe 100644 --- a/ext/pgsql/pgsql.c +++ b/ext/pgsql/pgsql.c @@ -2464,7 +2464,7 @@ PHP_FUNCTION(pg_lo_open) CHECK_PGSQL_LINK(link); } else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), - "Ols", &pgsql_link, pgsql_link_ce, &oid_long, &mode) == SUCCESS) { + "OlS", &pgsql_link, pgsql_link_ce, &oid_long, &mode) == SUCCESS) { if (oid_long <= (zend_long)InvalidOid) { zend_value_error("Invalid OID value passed"); RETURN_THROWS(); diff --git a/ext/pgsql/tests/gh10672.phpt b/ext/pgsql/tests/gh10672.phpt new file mode 100644 index 0000000000000..b9e0cf1385d10 --- /dev/null +++ b/ext/pgsql/tests/gh10672.phpt @@ -0,0 +1,43 @@ +--TEST-- +GH-10672 (pg_lo_open segfaults in the strict_types mode) +--EXTENSIONS-- +pgsql +--SKIPIF-- + +--FILE-- + "testing"]; +fee($a["bar"]); + +$db = pg_connect($conn_str); +pg_query($db, "DROP TABLE IF EXISTS gh10672"); +pg_query($db, "CREATE TABLE gh8253 (bar text);"); + +// Begin a transaction +pg_query($db, 'BEGIN'); + +// Create an empty large object +$oid = pg_lo_create($db); + +if ($oid === false) { + die(pg_last_error($db)); +} + +// Open the large object for writing +$lob = pg_lo_open($db, $oid, 'w'); + +if ($oid === false) { + die(pg_last_error($db)); +} + +echo 'The large object has been opened successfully.', PHP_EOL; +?> +--EXPECT-- +The large object has been opened successfully. From 2fd70ca1bbd3e5967271187df9d2e5c49c6472f3 Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Thu, 23 Feb 2023 14:40:42 +0000 Subject: [PATCH 2/2] Fix object name --- ext/pgsql/tests/gh10672.phpt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/pgsql/tests/gh10672.phpt b/ext/pgsql/tests/gh10672.phpt index b9e0cf1385d10..3f706e3048cef 100644 --- a/ext/pgsql/tests/gh10672.phpt +++ b/ext/pgsql/tests/gh10672.phpt @@ -18,7 +18,7 @@ fee($a["bar"]); $db = pg_connect($conn_str); pg_query($db, "DROP TABLE IF EXISTS gh10672"); -pg_query($db, "CREATE TABLE gh8253 (bar text);"); +pg_query($db, "CREATE TABLE gh10672 (bar text);"); // Begin a transaction pg_query($db, 'BEGIN');