diff options
author | Adam Harvey <aharvey@php.net> | 2015-02-02 11:07:34 +0000 |
---|---|---|
committer | Adam Harvey <aharvey@php.net> | 2015-02-02 11:07:34 +0000 |
commit | a7b3abe4e6f5e2fdfd8d55b676c9ca6b3f9c8cc8 (patch) | |
tree | 7ac46431e85176df9b2a9a5e5a7bf7d8b5c16999 | |
parent | fb803ff81993eb8acde0cdd5f513b6253221c349 (diff) | |
download | php-git-a7b3abe4e6f5e2fdfd8d55b676c9ca6b3f9c8cc8.tar.gz |
json_decode() should generate a syntax error when given "".
Fixes bug #68938 (json_decode() decodes empty string without error).
Patch by jeremy at bat-country dot us.
-rw-r--r-- | NEWS | 4 | ||||
-rw-r--r-- | ext/json/json.c | 1 | ||||
-rw-r--r-- | ext/json/tests/bug54484.phpt | 9 | ||||
-rw-r--r-- | ext/json/tests/bug68938.phpt | 11 |
4 files changed, 23 insertions, 2 deletions
@@ -24,6 +24,10 @@ PHP NEWS . Fixed bug #68571 (core dump when webserver close the socket). (redfoxli069 at gmail dot com, Laruence) +- JSON: + . Fixed bug #68938 (json_decode() decodes empty string without error). + (jeremy at bat-country dot us) + - Libxml: . Fixed bug #64938 (libxml_disable_entity_loader setting is shared between threads). (Martin Jansen) diff --git a/ext/json/json.c b/ext/json/json.c index 5b71eb06f6..27aed969d9 100644 --- a/ext/json/json.c +++ b/ext/json/json.c @@ -818,6 +818,7 @@ static PHP_FUNCTION(json_decode) JSON_G(error_code) = 0; if (!str_len) { + JSON_G(error_code) = PHP_JSON_ERROR_SYNTAX; RETURN_NULL(); } diff --git a/ext/json/tests/bug54484.phpt b/ext/json/tests/bug54484.phpt index d698ab5416..e56d8bd86b 100644 --- a/ext/json/tests/bug54484.phpt +++ b/ext/json/tests/bug54484.phpt @@ -15,11 +15,16 @@ json_decode("invalid json"); var_dump(json_last_error()); +json_decode("\001 invalid json"); +var_dump(json_last_error()); + + json_decode(""); var_dump(json_last_error()); ?> --EXPECT-- int(0) -int(0) int(4) -int(0) +int(4) +int(3) +int(4) diff --git a/ext/json/tests/bug68938.phpt b/ext/json/tests/bug68938.phpt new file mode 100644 index 0000000000..f6291ffe62 --- /dev/null +++ b/ext/json/tests/bug68938.phpt @@ -0,0 +1,11 @@ +--TEST-- +Bug #68938 (json_decode() decodes empty string without indicating error) +--SKIPIF-- +<?php if (!extension_loaded("json")) print "skip"; ?> +--FILE-- +<?php +json_decode(""); +var_dump(json_last_error()); +?> +--EXPECT-- +int(4) |