summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorHannes Magnusson <bjori@php.net>2007-07-24 22:57:13 +0000
committerHannes Magnusson <bjori@php.net>2007-07-24 22:57:13 +0000
commite3b8cf0f66bdb2765c17b633c4d9df4a51e6e025 (patch)
treee20fee0becd6c8d37e8d4692d2bbd6c226f4d2da /ext
parent3afa134717dcfc2e18efb17967c4210a84fec3c3 (diff)
downloadphp-git-e3b8cf0f66bdb2765c17b633c4d9df4a51e6e025.tar.gz
MFH: Fixed bug#42090 (json_decode causes segmentation fault)
Diffstat (limited to 'ext')
-rw-r--r--ext/json/json.c2
-rw-r--r--ext/json/tests/bug42090.phpt25
2 files changed, 26 insertions, 1 deletions
diff --git a/ext/json/json.c b/ext/json/json.c
index 5044f50b34..283021b365 100644
--- a/ext/json/json.c
+++ b/ext/json/json.c
@@ -470,7 +470,7 @@ static PHP_FUNCTION(json_decode)
RETURN_DOUBLE(d);
}
}
- if (*parameter == '"' && parameter[parameter_len-1] == '"') {
+ 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();
diff --git a/ext/json/tests/bug42090.phpt b/ext/json/tests/bug42090.phpt
new file mode 100644
index 0000000000..bccd28aba0
--- /dev/null
+++ b/ext/json/tests/bug42090.phpt
@@ -0,0 +1,25 @@
+--TEST--
+Bug#42090 (json_decode causes segmentation fault)
+--SKIPIF--
+<?php if (!extension_loaded("json")) print "skip"; ?>
+--FILE--
+<?php
+var_dump(
+ json_decode('""'),
+ json_decode('"..".'),
+ json_decode('"'),
+ json_decode('""""'),
+ json_encode('"'),
+ json_decode(json_encode('"')),
+ json_decode(json_encode('""'))
+);
+?>
+--EXPECT--
+string(0) ""
+string(5) "".."."
+string(1) """
+string(2) """"
+string(4) ""\"""
+string(1) """
+string(2) """"
+