summaryrefslogtreecommitdiff
path: root/ext/pgsql
diff options
context:
space:
mode:
authorIlia Alshanetsky <iliaa@php.net>2011-11-15 18:02:58 +0000
committerIlia Alshanetsky <iliaa@php.net>2011-11-15 18:02:58 +0000
commitb6530d8978aab57eebd17f6076035f786ae1693b (patch)
treeb589b812a75a39eba73f07e5a6c67c173f978806 /ext/pgsql
parent5f0e6a74baaf444b282f83f817e29d836487fce6 (diff)
downloadphp-git-b6530d8978aab57eebd17f6076035f786ae1693b.tar.gz
Fixed bug #60244 (pg_fetch_* functions do not validate that row param is >0).
Diffstat (limited to 'ext/pgsql')
-rw-r--r--ext/pgsql/pgsql.c18
-rw-r--r--ext/pgsql/tests/bug60244.phpt57
2 files changed, 75 insertions, 0 deletions
diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c
index e01816cc5b..336b980142 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;
@@ -4798,10 +4802,24 @@ PHP_FUNCTION(pg_get_notify)
if (result_type & PGSQL_NUM) {
add_index_string(return_value, 0, pgsql_notify->relname, 1);
add_index_long(return_value, 1, pgsql_notify->be_pid);
+#if HAVE_PQPROTOCOLVERSION && HAVE_PQPARAMETERSTATUS
+ if (PQprotocolVersion(pgsql) >= 3 && atof(PQparameterStatus(pgsql, "server_version")) >= 9.0) {
+#else
+ if (atof(PG_VERSION) >= 9.0) {
+#endif
+ add_index_string(return_value, 2, pgsql_notify->extra, 1);
+ }
}
if (result_type & PGSQL_ASSOC) {
add_assoc_string(return_value, "message", pgsql_notify->relname, 1);
add_assoc_long(return_value, "pid", pgsql_notify->be_pid);
+#if HAVE_PQPROTOCOLVERSION && HAVE_PQPARAMETERSTATUS
+ if (PQprotocolVersion(pgsql) >= 3 && atof(PQparameterStatus(pgsql, "server_version")) >= 9.0) {
+#else
+ if (atof(PG_VERSION) >= 9.0) {
+#endif
+ add_assoc_string(return_value, "payload", pgsql_notify->extra, 1);
+ }
}
PQfreemem(pgsql_notify);
}
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--
+<?php
+include("skipif.inc");
+?>
+--FILE--
+<?php
+
+include 'config.inc';
+
+$db = pg_connect($conn_str);
+$result = pg_query("select 'a' union select 'b'");
+
+var_dump(pg_fetch_array($result, -1));
+var_dump(pg_fetch_assoc($result, -1));
+var_dump(pg_fetch_object($result, -1));
+var_dump(pg_fetch_row($result, -1));
+
+var_dump(pg_fetch_array($result, 0));
+var_dump(pg_fetch_assoc($result, 0));
+var_dump(pg_fetch_object($result, 0));
+var_dump(pg_fetch_row($result, 0));
+
+pg_close($db);
+
+?>
+--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"
+}