Skip to content

Commit 9961494

Browse files
author
Scott MacVicar
committed
MFH: Invalid string causes segfault within json_decode()
1 parent b5ca904 commit 9961494

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ PHP NEWS
77
correctly with a non truecolour image, reported by Hamid Ebadi, APA Laboratory.
88
(Fixes CVE-2008-5498) (Scott)
99

10+
- Fixed segfault when malformed string passed to json_decode(). (Scott)
11+
1012
- Fixed bug #46889 (Memory leak in strtotime()). (Derick)
1113
- Fixed bug #46887 (Invalid calls to php_error_docref()).
1214
(oeriksson at mandriva dot com, Ilia)

ext/json/JSON_parser.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -494,9 +494,7 @@ JSON_parser(zval *z, unsigned short p[], int length, int assoc TSRMLS_DC)
494494
}
495495
*/
496496
case -7:
497-
if (type != -1 &&
498-
(JSON(the_stack)[JSON(the_top)] == MODE_OBJECT ||
499-
JSON(the_stack)[JSON(the_top)] == MODE_ARRAY))
497+
if (type != -1 && JSON(the_stack)[JSON(the_top)] == MODE_OBJECT)
500498
{
501499
zval *mval;
502500
smart_str_0(&buf);
@@ -566,9 +564,7 @@ JSON_parser(zval *z, unsigned short p[], int length, int assoc TSRMLS_DC)
566564
*/
567565
case -5:
568566
{
569-
if (type != -1 &&
570-
(JSON(the_stack)[JSON(the_top)] == MODE_OBJECT ||
571-
JSON(the_stack)[JSON(the_top)] == MODE_ARRAY))
567+
if (type != -1 && JSON(the_stack)[JSON(the_top)] == MODE_ARRAY)
572568
{
573569
zval *mval;
574570
smart_str_0(&buf);

ext/json/tests/001.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ var_dump(json_decode(";"));
1616
var_dump(json_decode("руссиш"));
1717
var_dump(json_decode("blah"));
1818
var_dump(json_decode(NULL));
19+
var_dump(json_decode('[1}'));
1920
var_dump(json_decode('{ "test": { "foo": "bar" } }'));
2021
var_dump(json_decode('{ "test": { "foo": "" } }'));
2122
var_dump(json_decode('{ "": { "foo": "" } }'));
@@ -38,6 +39,7 @@ string(1) ";"
3839
string(12) "руссиш"
3940
string(4) "blah"
4041
NULL
42+
NULL
4143
object(stdClass)#1 (1) {
4244
["test"]=>
4345
object(stdClass)#2 (1) {

0 commit comments

Comments
 (0)