summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/json/json.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/ext/json/json.c b/ext/json/json.c
index 347f100dcd..9f86daa004 100644
--- a/ext/json/json.c
+++ b/ext/json/json.c
@@ -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);
}