diff --git a/.github/scripts/windows/test_task.bat b/.github/scripts/windows/test_task.bat index 223d6543003..7c526be95c3 100644 --- a/.github/scripts/windows/test_task.bat +++ b/.github/scripts/windows/test_task.bat @@ -36,8 +36,7 @@ if %errorlevel% neq 0 exit /b 3 rem setup PostgreSQL related exts set PGUSER=postgres set PGPASSWORD=Password12! -rem set PGSQL_TEST_CONNSTR=host=127.0.0.1 dbname=test port=5432 user=postgres password=Password12! -echo ^ >> "./ext/pgsql/tests/config.inc" +set PGSQL_TEST_CONNSTR=host=127.0.0.1 dbname=test port=5432 user=%PGUSER% password=%PGPASSWORD% set PDO_PGSQL_TEST_DSN=pgsql:host=127.0.0.1 port=5432 dbname=test user=%PGUSER% password=%PGPASSWORD% set TMP_POSTGRESQL_BIN=%PGBIN% "%TMP_POSTGRESQL_BIN%\createdb.exe" test diff --git a/NEWS b/NEWS index 882a17d2ed3..6960722a611 100644 --- a/NEWS +++ b/NEWS @@ -60,6 +60,8 @@ PHP NEWS - PgSql: . Fix memory leak when first string conversion fails. (nielsdos) + . Fix segfaults when attempting to fetch row into a non-instantiable class + name. (Girgias, nielsdos) - Phar: . Fix memory leak of argument in webPhar. (nielsdos) diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c index 7a96fe8f20e..68b25df4e15 100644 --- a/ext/pgsql/pgsql.c +++ b/ext/pgsql/pgsql.c @@ -2064,7 +2064,10 @@ static void php_pgsql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, zend_long result_ zval dataset; ZVAL_COPY_VALUE(&dataset, return_value); - object_init_ex(return_value, ce); + zend_result obj_initialized = object_init_ex(return_value, ce); + if (UNEXPECTED(obj_initialized == FAILURE)) { + RETURN_THROWS(); + } if (!ce->default_properties_count && !ce->__set) { Z_OBJ_P(return_value)->properties = Z_ARR(dataset); } else { diff --git a/ext/pgsql/tests/inc/config.inc b/ext/pgsql/tests/inc/config.inc index b01b120723d..dc95c9eedab 100644 --- a/ext/pgsql/tests/inc/config.inc +++ b/ext/pgsql/tests/inc/config.inc @@ -6,4 +6,3 @@ // "test" database must exist. i.e. "createdb test" before testing $conn_str = getenv('PGSQL_TEST_CONNSTR') ?: "host=localhost dbname=test port=5432 user=postgres password=postgres"; // connection string -?> diff --git a/ext/pgsql/tests/inc/lcmess.inc b/ext/pgsql/tests/inc/lcmess.inc index 7c6e0b80ed7..a1bf61e6851 100644 --- a/ext/pgsql/tests/inc/lcmess.inc +++ b/ext/pgsql/tests/inc/lcmess.inc @@ -17,5 +17,3 @@ function _set_lc_messages($conn, $lc_messages = 'C') return true; } - -?> diff --git a/ext/pgsql/tests/inc/skipif.inc b/ext/pgsql/tests/inc/skipif.inc index 06c3ff65711..2ce5f46e778 100644 --- a/ext/pgsql/tests/inc/skipif.inc +++ b/ext/pgsql/tests/inc/skipif.inc @@ -1,4 +1,3 @@ - = 9.0\n"); } } - -?> diff --git a/ext/pgsql/tests/pg_fetch_object_with_abstract_class.phpt b/ext/pgsql/tests/pg_fetch_object_with_abstract_class.phpt new file mode 100644 index 00000000000..d04e66a043b --- /dev/null +++ b/ext/pgsql/tests/pg_fetch_object_with_abstract_class.phpt @@ -0,0 +1,59 @@ +--TEST-- +pg_fetch_object() with abstract class name +--EXTENSIONS-- +pgsql +--SKIPIF-- + +--FILE-- +getMessage(), PHP_EOL; +} + +try { + $result = pg_query($db, $sql); + var_dump(pg_fetch_object($result, NULL, 'C')); +} catch(Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +try { + $result = pg_query($db, $sql); + var_dump(pg_fetch_object($result, NULL, 'E')); +} catch(Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +?> +--CLEAN-- + +--EXPECT-- +Error: Cannot instantiate interface I +Error: Cannot instantiate abstract class C +Error: Cannot instantiate enum E