]> granicus.if.org Git - php/commitdiff
MFH Fix bug #45989 - json_decode() doesn't return NULL on certain invalid strings
authorScott MacVicar <scottmac@php.net>
Thu, 12 Feb 2009 00:36:23 +0000 (00:36 +0000)
committerScott MacVicar <scottmac@php.net>
Thu, 12 Feb 2009 00:36:23 +0000 (00:36 +0000)
ext/json/json.c
ext/json/tests/001.phpt
ext/json/tests/bug42090.phpt

index 2c6f8642d105071fa57efe2cf905505bd43e3f2d..70d704203d46db83c3893de2afcbf0c9e10c1174 100644 (file)
@@ -479,13 +479,7 @@ static PHP_FUNCTION(json_decode)
                        RETURN_DOUBLE(d);
                }
        }
-       if (parameter_len > 1 && *parameter == '"' && parameter[parameter_len-1] == '"') {
-               RETURN_STRINGL(parameter+1, parameter_len-2, 1);
-       } else if (*parameter == '{' || *parameter == '[') { /* invalid JSON string */
                RETURN_NULL();
-       } else {
-               RETURN_STRINGL(parameter, parameter_len, 1);
-       }
     }
 }
 /* }}} */
index e227e978eb44280cad5886a6fa3065bfaabc2e50..02d43c424390d327af3e92980f621b178fdd07f4 100644 (file)
@@ -16,7 +16,6 @@ var_dump(json_decode(";"));
 var_dump(json_decode("руссиш"));
 var_dump(json_decode("blah"));
 var_dump(json_decode(NULL));
-var_dump(json_decode('[1}'));
 var_dump(json_decode('{ "test": { "foo": "bar" } }'));
 var_dump(json_decode('{ "test": { "foo": "" } }'));
 var_dump(json_decode('{ "": { "foo": "" } }'));
@@ -32,12 +31,11 @@ NULL
 NULL
 NULL
 NULL
-string(1) "."
-string(1) "."
-string(3) "<?>"
-string(1) ";"
-string(12) "руссиш"
-string(4) "blah"
+NULL
+NULL
+NULL
+NULL
+NULL
 NULL
 NULL
 object(stdClass)#%d (1) {
index bccd28aba0dcb64188d1534da537be743cd680ea..9e5b3317e5411abe6e652e95a70b49e01d8b6d2b 100644 (file)
@@ -1,5 +1,5 @@
 --TEST--
-Bug#42090 (json_decode causes segmentation fault)
+Bug #42090 (json_decode causes segmentation fault)
 --SKIPIF--
 <?php if (!extension_loaded("json")) print "skip"; ?>
 --FILE--
@@ -16,10 +16,9 @@ var_dump(
 ?>
 --EXPECT--
 string(0) ""
-string(5) "".."."
-string(1) """
-string(2) """"
+NULL
+NULL
+NULL
 string(4) ""\"""
 string(1) """
 string(2) """"
-