From 0ace9f4885d261b14a0492124c9aa4939abd7f5f Mon Sep 17 00:00:00 2001 From: Marcus Boerger Date: Mon, 15 Mar 2004 19:47:18 +0000 Subject: [PATCH] Bugfix #27597 pg_fetch_array not returning false . --- NEWS | 1 + ext/pgsql/pgsql.c | 10 ++++-- ext/pgsql/tests/80_bug27597.phpt | 60 ++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 3 deletions(-) create mode 100755 ext/pgsql/tests/80_bug27597.phpt diff --git a/NEWS b/NEWS index cc23ce7c7f..d6fa3a380e 100644 --- a/NEWS +++ b/NEWS @@ -46,6 +46,7 @@ PHP NEWS - Fixed problem preventing startup errors from being displayed. (Marcus) - Fixed start-up problem if both SPL and SimpleXML were enabled. The double initialization of apache 1.3 was causing problems here. (Marcus, Derick) +- Fixed bug #27597 (pg_fetch_array not returning false). (Marcus) - Fixed bug #27586 (ArrayObject::getIterator crashes with [] assignment). (Marcus) - Fixed bug #27537 (Objects pointing to each other segfaults). (Dmitry) diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c index 914ad66d65..2fb1a3075d 100644 --- a/ext/pgsql/pgsql.c +++ b/ext/pgsql/pgsql.c @@ -1403,7 +1403,7 @@ PHP_FUNCTION(pg_fetch_result) /* {{{ void php_pgsql_fetch_hash */ static void php_pgsql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, long result_type, int into_object) { - zval *result; + zval *result, *zrow; PGresult *pgsql_result; pgsql_result_handle *pg_result; int i, num_fields, pgsql_row, use_row; @@ -1432,10 +1432,14 @@ static void php_pgsql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, long result_type, result_type = PGSQL_ASSOC; use_row = 0; } else { - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|ll", &result, &row, &result_type) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|zl", &result, &zrow, &result_type) == FAILURE) { return; } - use_row = ZEND_NUM_ARGS() > 1; + use_row = ZEND_NUM_ARGS() > 1 && Z_TYPE_P(zrow) != IS_NULL; + if (use_row) { + convert_to_long_ex(&zrow); + row = Z_LVAL_P(zrow); + } } if (!(result_type & PGSQL_BOTH)) { diff --git a/ext/pgsql/tests/80_bug27597.phpt b/ext/pgsql/tests/80_bug27597.phpt new file mode 100755 index 0000000000..aa04a4a225 --- /dev/null +++ b/ext/pgsql/tests/80_bug27597.phpt @@ -0,0 +1,60 @@ +--TEST-- +Bug #27597 pg_fetch_array not returning false +--SKIPIF-- + +--FILE-- + 4) { + echo "ENDLESS-LOOP"; + exit(1); + } +} + +pg_close($dbh); + +?> +===DONE=== +--EXPECTF-- +Array +( + [id] => 0 +) +Array +( + [id] => 1 +) +Array +( + [id] => 2 +) +Array +( + [id] => 3 +) +===DONE=== -- 2.40.0