From 4cf3c8c5585bba9f1664599df0f3be4cffcb24d5 Mon Sep 17 00:00:00 2001 From: Ilia Alshanetsky Date: Tue, 15 Nov 2011 18:02:58 +0000 Subject: [PATCH] Fixed bug #60244 (pg_fetch_* functions do not validate that row param is >0). --- ext/pgsql/pgsql.c | 4 +++ ext/pgsql/tests/bug60244.phpt | 57 +++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 ext/pgsql/tests/bug60244.phpt diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c index a82271776c..8f979b7391 100644 --- a/ext/pgsql/pgsql.c +++ b/ext/pgsql/pgsql.c @@ -2452,6 +2452,10 @@ static void php_pgsql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, long result_type, } else { convert_to_long(zrow); row = Z_LVAL_P(zrow); + if (row < 0) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "The row parameter must be greater or equal to zero"); + RETURN_FALSE; + } } use_row = ZEND_NUM_ARGS() > 1 && row != -1; diff --git a/ext/pgsql/tests/bug60244.phpt b/ext/pgsql/tests/bug60244.phpt new file mode 100644 index 0000000000..94568b6031 --- /dev/null +++ b/ext/pgsql/tests/bug60244.phpt @@ -0,0 +1,57 @@ +--TEST-- +Bug #60244 (pg_fetch_* functions do not validate that row param is >0) +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +Warning: pg_fetch_array(): The row parameter must be greater or equal to zero in %sbug60244.php on line %d +bool(false) + +Warning: pg_fetch_assoc(): The row parameter must be greater or equal to zero in %sbug60244.php on line %d +bool(false) + +Warning: pg_fetch_object(): The row parameter must be greater or equal to zero in %sbug60244.php on line %d +bool(false) + +Warning: pg_fetch_row(): The row parameter must be greater or equal to zero in %sbug60244.php on line %d +bool(false) +array(2) { + [0]=> + string(1) "a" + ["?column?"]=> + string(1) "a" +} +array(1) { + ["?column?"]=> + string(1) "a" +} +object(stdClass)#1 (1) { + ["?column?"]=> + string(1) "a" +} +array(1) { + [0]=> + string(1) "a" +} -- 2.50.1