From 7cc6a237c6aa3fef2793edbf0f9ddd2e92bdfe81 Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Sat, 24 Aug 2013 10:13:01 +0200 Subject: [PATCH] increase parser strictness for php --- 90.patch | 28 +++++++++++++++++ 94.patch | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++ json-c.spec | 12 +++++++- 3 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 90.patch create mode 100644 94.patch diff --git a/90.patch b/90.patch new file mode 100644 index 0000000..8f32ecf --- /dev/null +++ b/90.patch @@ -0,0 +1,28 @@ +From e9ee4ae18a9fca8c31eac44669364034658b3d51 Mon Sep 17 00:00:00 2001 +From: Remi Collet +Date: Thu, 13 Jun 2013 13:40:01 +0200 +Subject: [PATCH] in strick mode, number must not start with 0 + +--- + json_tokener.c | 5 +++++ + 1 file changed, 5 insertions(+) + +diff --git a/json_tokener.c b/json_tokener.c +index b2b47f9..4491cec 100644 +--- a/json_tokener.c ++++ b/json_tokener.c +@@ -611,6 +611,11 @@ struct json_object* json_tokener_parse_ex(struct json_tokener *tok, + int64_t num64; + double numd; + if (!tok->is_double && json_parse_int64(tok->pb->buf, &num64) == 0) { ++ if (num64 && tok->pb->buf[0]=='0' && (tok->flags & JSON_TOKENER_STRICT)) { ++ /* in strick mode, number must not start with 0 */ ++ tok->err = json_tokener_error_parse_number; ++ goto out; ++ } + current = json_object_new_int64(num64); + } else if(tok->is_double && json_parse_double(tok->pb->buf, &numd) == 0) { + current = json_object_new_double(numd); +-- +1.8.1.6 + diff --git a/94.patch b/94.patch new file mode 100644 index 0000000..f507ff0 --- /dev/null +++ b/94.patch @@ -0,0 +1,88 @@ +From a07ef3d19763094ab35cc009657c85bcbb9dd9ae Mon Sep 17 00:00:00 2001 +From: Remi Collet +Date: Tue, 6 Aug 2013 10:41:14 +0200 +Subject: [PATCH 1/3] no single-quote string in strict mode + +--- + json_tokener.c | 7 ++++++- + 1 file changed, 6 insertions(+), 1 deletion(-) + +diff --git a/json_tokener.c b/json_tokener.c +index a6924a1..45390ac 100644 +--- a/json_tokener.c ++++ b/json_tokener.c +@@ -293,8 +293,13 @@ struct json_object* json_tokener_parse_ex(struct json_tokener *tok, + printbuf_reset(tok->pb); + tok->st_pos = 0; + goto redo_char; +- case '"': + case '\'': ++ if (tok->flags & JSON_TOKENER_STRICT) { ++ /* in STRICT mode only double-quote are allowed */ ++ tok->err = json_tokener_error_parse_unexpected; ++ goto out; ++ } ++ case '"': + state = json_tokener_state_string; + printbuf_reset(tok->pb); + tok->quote_char = c; +-- +1.8.1.6 + + +From 87fa32dfe013d961ced5252ffacef0beefc8f62f Mon Sep 17 00:00:00 2001 +From: Remi Collet +Date: Wed, 21 Aug 2013 15:41:40 +0200 +Subject: [PATCH 2/3] no comment in strict mode + +--- + json_tokener.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/json_tokener.c b/json_tokener.c +index 45390ac..7ce53ca 100644 +--- a/json_tokener.c ++++ b/json_tokener.c +@@ -265,7 +265,7 @@ struct json_object* json_tokener_parse_ex(struct json_tokener *tok, + if ((!ADVANCE_CHAR(str, tok)) || (!PEEK_CHAR(c, tok))) + goto out; + } +- if(c == '/') { ++ if(c == '/' && !(tok->flags & JSON_TOKENER_STRICT)) { + printbuf_reset(tok->pb); + printbuf_memappend_fast(tok->pb, &c, 1); + state = json_tokener_state_comment_start; +-- +1.8.1.6 + + +From 4039f91cab283b483094dbe59202818bb1733d66 Mon Sep 17 00:00:00 2001 +From: Remi Collet +Date: Fri, 23 Aug 2013 13:40:01 +0200 +Subject: [PATCH 3/3] trailing char not allowed in strict mode + +--- + json_tokener.c | 7 +++++++ + 1 file changed, 7 insertions(+) + +diff --git a/json_tokener.c b/json_tokener.c +index 7ce53ca..def6e10 100644 +--- a/json_tokener.c ++++ b/json_tokener.c +@@ -769,6 +769,13 @@ struct json_object* json_tokener_parse_ex(struct json_tokener *tok, + } /* while(POP_CHAR) */ + + out: ++ if (c && ++ (state == json_tokener_state_finish) && ++ (tok->depth == 0) && ++ (tok->flags & JSON_TOKENER_STRICT)) { ++ /* unexpected char after JSON data */ ++ tok->err = json_tokener_error_parse_unexpected; ++ } + if (!c) { /* We hit an eof char (0) */ + if(state != json_tokener_state_finish && + saved_state != json_tokener_state_finish) +-- +1.8.1.6 + diff --git a/json-c.spec b/json-c.spec index 6203cfd..271d525 100644 --- a/json-c.spec +++ b/json-c.spec @@ -2,13 +2,17 @@ Name: json-c Version: 0.11 -Release: 2%{?dist} +Release: 3%{?dist} Summary: A JSON implementation in C Group: Development/Libraries License: MIT URL: https://github.com/json-c/json-c/wiki Source0: https://github.com/json-c/json-c/archive/json-c-%{version}-%{reldate}.tar.gz +# increaser parser strictness (for php compatibility) +Patch0: https://github.com/json-c/json-c/pull/90.patch +Patch1: https://github.com/json-c/json-c/pull/94.patch + BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX) BuildRequires: libtool @@ -40,6 +44,9 @@ This package contains the reference manual for json-c. %prep %setup -q -n json-c-json-c-%{version}-%{reldate} +%patch0 -p1 -b .strict90 +%patch1 -p1 -b .strict94 + for doc in ChangeLog; do iconv -f iso-8859-1 -t utf8 $doc > $doc.new && touch -r $doc $doc.new && @@ -100,6 +107,9 @@ rm -rf %{buildroot} %changelog +* Sat Aug 24 2013 Remi Collet - 0.11-3 +- increase parser strictness for php + * Sat Aug 03 2013 Fedora Release Engineering - 0.11-2 - Rebuilt for https://fedoraproject.org/wiki/Fedora_20_Mass_Rebuild