]> granicus.if.org Git - php/commitdiff
Adjust logic in sanity checks.
authorJeff Welch <whatthejeff@gmail.com>
Sun, 8 Mar 2015 15:31:26 +0000 (11:31 -0400)
committerJeff Welch <whatthejeff@gmail.com>
Sun, 8 Mar 2015 19:27:41 +0000 (15:27 -0400)
The code should return false when the provided options argument is neither an
array nor a valid filter.

ext/filter/filter.c
ext/filter/tests/057.phpt [new file with mode: 0644]

index 107ba8637483205804115085cacca586a4723247..475cfccb2edd1185b867191c8d291e25b46de6e8 100644 (file)
@@ -800,7 +800,7 @@ PHP_FUNCTION(filter_input_array)
                return;
        }
 
-       if (op && (Z_TYPE_P(op) != IS_ARRAY) && (Z_TYPE_P(op) == IS_LONG && !PHP_FILTER_ID_EXISTS(Z_LVAL_P(op)))) {
+       if (op && (Z_TYPE_P(op) != IS_ARRAY) && !(Z_TYPE_P(op) == IS_LONG && PHP_FILTER_ID_EXISTS(Z_LVAL_P(op)))) {
                RETURN_FALSE;
        }
 
@@ -845,7 +845,7 @@ PHP_FUNCTION(filter_var_array)
                return;
        }
 
-       if (op && (Z_TYPE_P(op) != IS_ARRAY) && (Z_TYPE_P(op) == IS_LONG && !PHP_FILTER_ID_EXISTS(Z_LVAL_P(op)))) {
+       if (op && (Z_TYPE_P(op) != IS_ARRAY) && !(Z_TYPE_P(op) == IS_LONG && PHP_FILTER_ID_EXISTS(Z_LVAL_P(op)))) {
                RETURN_FALSE;
        }
 
diff --git a/ext/filter/tests/057.phpt b/ext/filter/tests/057.phpt
new file mode 100644 (file)
index 0000000..93ab3ee
--- /dev/null
@@ -0,0 +1,23 @@
+--TEST--
+filter_input_array() and filter_var_array() with invalid $definition arguments
+--SKIPIF--
+<?php if (!extension_loaded("filter")) die("skip"); ?>
+--FILE--
+<?php
+foreach (array(null, true, false, 1, "", new stdClass) as $invalid) {
+    var_dump(filter_input_array(INPUT_POST, $invalid));
+    var_dump(filter_var_array(array(), $invalid));
+}
+--EXPECT--
+bool(false)
+bool(false)
+bool(false)
+bool(false)
+bool(false)
+bool(false)
+bool(false)
+bool(false)
+bool(false)
+bool(false)
+bool(false)
+bool(false)