diff options
author | Hannes Magnusson <bjori@php.net> | 2007-07-24 22:57:13 +0000 |
---|---|---|
committer | Hannes Magnusson <bjori@php.net> | 2007-07-24 22:57:13 +0000 |
commit | e3b8cf0f66bdb2765c17b633c4d9df4a51e6e025 (patch) | |
tree | e20fee0becd6c8d37e8d4692d2bbd6c226f4d2da /ext | |
parent | 3afa134717dcfc2e18efb17967c4210a84fec3c3 (diff) | |
download | php-git-e3b8cf0f66bdb2765c17b633c4d9df4a51e6e025.tar.gz |
MFH: Fixed bug#42090 (json_decode causes segmentation fault)
Diffstat (limited to 'ext')
-rw-r--r-- | ext/json/json.c | 2 | ||||
-rw-r--r-- | ext/json/tests/bug42090.phpt | 25 |
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) """" + |