]> granicus.if.org Git - php/commitdiff
MFB:- Fixed bug #38680 (Added missing handling of basic types in json_decode)
authorJani Taskinen <jani@php.net>
Tue, 22 Jul 2008 17:06:00 +0000 (17:06 +0000)
committerJani Taskinen <jani@php.net>
Tue, 22 Jul 2008 17:06:00 +0000 (17:06 +0000)
# This was claimed to be in HEAD but wasn't..some commit reverted it or
# someone didn't check for real..

ext/json/json.c

index 347f100dcd9f052ba5c927f91a38c26ad956d938..9f86daa0040500e1de6979a478aa1652acb876d1 100644 (file)
@@ -545,6 +545,8 @@ static PHP_FUNCTION(json_decode)
                }
                if (str_len > 1 && *str.s == '"' && str.s[str_len-1] == '"') {
                        RETURN_STRINGL(str.s+1, str_len-2, 1);
+               } else if (*str.s == '{' || *str.s == '[') { /* invalid JSON string */
+                       RETURN_NULL();
                } else {
                        RETURN_STRINGL(str.s, str_len, 1);
                }
@@ -576,6 +578,8 @@ static PHP_FUNCTION(json_decode)
                }
                if (str_len > 1 && *str.u == 0x22 /*'"'*/ && str.u[str_len-1] == 0x22 /*'"'*/) {
                        RETURN_UNICODEL(str.u+1, str_len-2, 1);
+               } else if (*str.u == 0x7b /*'{'*/ || *str.u == 0x5b /*'['*/ ) { /* invalid JSON string */
+                       RETURN_NULL();
                } else {
                        RETURN_UNICODEL(str.u, str_len, 1);
                }