Skip to content
Browse files

MFH: Fixed bug#42090 (json_decode causes segmentation fault)

  • Loading branch information...
1 parent 3afa134 commit e3b8cf0f66bdb2765c17b633c4d9df4a51e6e025 @bjori bjori committed Jul 24, 2007
Showing with 27 additions and 1 deletion.
  1. +1 −0 NEWS
  2. +1 −1 ext/json/json.c
  3. +25 −0 ext/json/tests/bug42090.phpt
View
1 NEWS
@@ -64,6 +64,7 @@ PHP NEWS
- Fixed PECL bug #11216 (crash in ZipArchive::addEmptyDir when a directory
already exists). (Pierre)
+- Fixed bug #42090 (json_decode causes segmentation fault). (Hannes)
- Fixed bug #42072 (No warning message for clearstatcache() with arguments).
(Ilia)
- Fixed bug #42071 (ini scanner allows using NULL as option name). (Jani)
View
2 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();
View
25 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) """"
+

0 comments on commit e3b8cf0

Please sign in to comment.
Something went wrong with that request. Please try again.