Compare commits

..

10 Commits

Author SHA1 Message Date
openeuler-ci-bot
525d3092cb
!79 [sync] PR-76: backport patches
From: @openeuler-sync-bot 
Reviewed-by: @dillon_chen 
Signed-off-by: @dillon_chen
2025-03-19 07:07:48 +00:00
sun_haii_10
f3a34be86a backport patches
(cherry picked from commit 55884d2a03bcbf977c752a1a383c8064805ee55c)
2025-03-18 15:31:47 +08:00
openeuler-ci-bot
2a3797896a
!73 [sync] PR-70: Fix the apps/json_parse -s (strict) option, default to non-strict
From: @openeuler-sync-bot 
Reviewed-by: @dillon_chen 
Signed-off-by: @dillon_chen
2024-12-06 09:43:22 +00:00
sun_hai_10
7940705d3f Fix the apps/json_parse -s (strict) option, default to non-strict
(cherry picked from commit 536e8a4eb4207fe720989a513b5a01ab8597f6a9)
2024-12-06 17:28:41 +08:00
openeuler-ci-bot
0d47b2e33a
!69 [sync] PR-67: backport upstream patch
From: @openeuler-sync-bot 
Reviewed-by: @dillon_chen 
Signed-off-by: @dillon_chen
2024-12-06 08:10:27 +00:00
yueyuankun
5501449e5c backport upstream patch
(cherry picked from commit 73ac674f0a01befdc77102ec85aa9ba242162473)
2024-12-05 16:37:52 +08:00
openeuler-ci-bot
2a95db741c
!64 [sync] PR-63: Take 2 fixing the placement of json_tokener_error_memory in the enum
From: @openeuler-sync-bot 
Reviewed-by: @licihua 
Signed-off-by: @licihua
2024-09-25 01:50:07 +00:00
sun_hai_10
3eea77c225 Take 2 fixing the placement of json_tokener_error_memory in the enum.
(cherry picked from commit 5adf298743c2808d92a6076682c989b65f8af2b8)
2024-09-24 17:30:57 +08:00
openeuler-ci-bot
de6f4f35da
!60 [sync] PR-58: backport upstream patch
From: @openeuler-sync-bot 
Reviewed-by: @dillon_chen 
Signed-off-by: @dillon_chen
2024-06-26 08:17:14 +00:00
liweigang
94a82016bb backport upstream patch
Signed-off-by: liweigang <liweiganga@uniontech.com>
(cherry picked from commit b09a490c6fbcdc3e5a0c2f297f604c44a41e0664)
2024-06-26 15:48:24 +08:00
10 changed files with 577 additions and 2 deletions

View File

@ -0,0 +1,172 @@
From 565f181f656439847ef79650caad5c0b6c20171b Mon Sep 17 00:00:00 2001
From: Eric Hawicz <erh+git@nimenees.com>
Date: Fri, 8 Nov 2024 22:20:40 -0500
Subject: [PATCH] Fix issue #875: cast to unsigned char so bytes above 0x7f
aren't interpreted as negative, which was causing the strict-mode control
characters check to incorrectly trigger.
---
json_tokener.c | 2 +-
tests/test_parse.c | 17 ++++++++++++++---
tests/test_parse.expected | 13 ++++++++++---
3 files changed, 25 insertions(+), 7 deletions(-)
diff --git a/json_tokener.c b/json_tokener.c
index c831f8a..773229e 100644
--- a/json_tokener.c
+++ b/json_tokener.c
@@ -678,7 +678,7 @@ struct json_object *json_tokener_parse_ex(struct json_tokener *tok, const char *
state = json_tokener_state_string_escape;
break;
}
- else if ((tok->flags & JSON_TOKENER_STRICT) && c <= 0x1f)
+ else if ((tok->flags & JSON_TOKENER_STRICT) && (unsigned char)c <= 0x1f)
{
// Disallow control characters in strict mode
tok->err = json_tokener_error_parse_string;
diff --git a/tests/test_parse.c b/tests/test_parse.c
index d664a31..525f68c 100644
--- a/tests/test_parse.c
+++ b/tests/test_parse.c
@@ -297,6 +297,7 @@ struct incremental_step
{"d", -1, -1, json_tokener_continue, 0, 0},
{"1", -1, -1, json_tokener_continue, 0, 0},
{"e\"", -1, -1, json_tokener_success, 1, 0},
+
/* parse two char at every time */
{"\"\\u", -1, -1, json_tokener_continue, 0, 0},
{"d8", -1, -1, json_tokener_continue, 0, 0},
@@ -322,6 +323,11 @@ struct incremental_step
{"\"fff \\ud83d\\ude", -1, -1, json_tokener_continue, 0, 0},
{"00 bar\"", -1, -1, json_tokener_success, 1, 0},
+ /* Check a utf-8 char (a+umlaut) that has bytes that look negative when
+ char are signed (see also control char check below) */
+ {"\"\xc3\xa4\"", -1, -1, json_tokener_success, 1, 0},
+ {"\"\xc3\xa4\"", -1, -1, json_tokener_success, 1, JSON_TOKENER_STRICT},
+
/* Check that json_tokener_reset actually resets */
{"{ \"foo", -1, -1, json_tokener_continue, 1, 0},
{": \"bar\"}", -1, 0, json_tokener_error_parse_unexpected, 1, 0},
@@ -394,8 +400,8 @@ struct incremental_step
{"Infinity", 9, 8, json_tokener_success, 1, 0},
{"infinity", 9, 8, json_tokener_success, 1, 0},
- {"-infinity", 10, 9, json_tokener_success, 1, 0},
{"infinity", 9, 0, json_tokener_error_parse_unexpected, 1, JSON_TOKENER_STRICT},
+ {"-infinity", 10, 9, json_tokener_success, 1, 0},
{"-infinity", 10, 1, json_tokener_error_parse_unexpected, 1, JSON_TOKENER_STRICT},
{"inf", 3, 3, json_tokener_continue, 0, 0},
@@ -462,12 +468,15 @@ struct incremental_step
{"[18446744073709551616]", 23, 21, json_tokener_error_parse_number, 1, JSON_TOKENER_STRICT},
/* XXX this seems like a bug, should fail with _error_parse_number instead */
+ {"18446744073709551616", 21, 20, json_tokener_success, 1, 0},
{"18446744073709551616", 21, 20, json_tokener_error_parse_eof, 1, JSON_TOKENER_STRICT},
/* Exceeding integer limits as double parse OK */
{"[9223372036854775808.0]", 24, 23, json_tokener_success, 1, 0},
+ {"[-9223372036854775809.0]", 25, 24, json_tokener_success, 1, 0},
{"[-9223372036854775809.0]", 25, 24, json_tokener_success, 1, JSON_TOKENER_STRICT},
{"[18446744073709551615.0]", 25, 24, json_tokener_success, 1, 0},
+ {"[18446744073709551616.0]", 25, 24, json_tokener_success, 1, 0},
{"[18446744073709551616.0]", 25, 24, json_tokener_success, 1, JSON_TOKENER_STRICT},
/* offset=1 because "n" is the start of "null". hmm... */
@@ -524,6 +533,7 @@ struct incremental_step
{"\"\\a\"", -1, 2, json_tokener_error_parse_string, 1, 0},
/* Check '\'' in strict model */
+ {"\'foo\'", -1, 5, json_tokener_success, 1, 0},
{"\'foo\'", -1, 0, json_tokener_error_parse_unexpected, 1, JSON_TOKENER_STRICT},
/* Parse array/object */
@@ -544,9 +554,10 @@ struct incremental_step
* in what we accept (up to a point).
*/
{"[1,2,3,]", -1, -1, json_tokener_success, 0, 0},
+ {"[1,2,3,]", -1, 7, json_tokener_error_parse_unexpected, 1, JSON_TOKENER_STRICT},
{"[1,2,,3,]", -1, 5, json_tokener_error_parse_unexpected, 0, 0},
+ {"[1,2,,3,]", -1, 5, json_tokener_error_parse_unexpected, 0, JSON_TOKENER_STRICT},
- {"[1,2,3,]", -1, 7, json_tokener_error_parse_unexpected, 1, JSON_TOKENER_STRICT},
{"{\"a\":1,}", -1, 7, json_tokener_error_parse_unexpected, 1, JSON_TOKENER_STRICT},
// utf-8 test
@@ -656,7 +667,7 @@ static void test_incremental_parse(void)
printf("json_tokener_parse(%s) ... ", string_to_parse);
new_obj = json_tokener_parse(string_to_parse);
if (new_obj == NULL)
- puts("got error as expected");
+ printf("%s", "got error as expected\n");
/* test incremental parsing in various forms */
tok = json_tokener_new();
diff --git a/tests/test_parse.expected b/tests/test_parse.expected
index 82db5db..cc5dd10 100644
--- a/tests/test_parse.expected
+++ b/tests/test_parse.expected
@@ -134,6 +134,8 @@ json_tokener_parse_ex(tok, "fff \ud834\udd, 15) ... OK: got correct error: cont
json_tokener_parse_ex(tok, 1e bar" , 7) ... OK: got object of type [string]: "fff 𝄞 bar"
json_tokener_parse_ex(tok, "fff \ud83d\ude, 15) ... OK: got correct error: continue
json_tokener_parse_ex(tok, 00 bar" , 7) ... OK: got object of type [string]: "fff 😀 bar"
+json_tokener_parse_ex(tok, "ä" , 4) ... OK: got object of type [string]: "ä"
+json_tokener_parse_ex(tok, "ä" , 4) ... OK: got object of type [string]: "ä"
json_tokener_parse_ex(tok, { "foo , 6) ... OK: got correct error: continue
json_tokener_parse_ex(tok, : "bar"} , 8) ... OK: got correct error: unexpected character
json_tokener_parse_ex(tok, { "foo , 6) ... OK: got correct error: continue
@@ -177,8 +179,8 @@ json_tokener_parse_ex(tok, null , 4) ... OK: got correct error: continu
json_tokener_parse_ex(tok, null , 5) ... OK: got object of type [null]: null
json_tokener_parse_ex(tok, Infinity , 9) ... OK: got object of type [double]: Infinity
json_tokener_parse_ex(tok, infinity , 9) ... OK: got object of type [double]: Infinity
-json_tokener_parse_ex(tok, -infinity , 10) ... OK: got object of type [double]: -Infinity
json_tokener_parse_ex(tok, infinity , 9) ... OK: got correct error: unexpected character
+json_tokener_parse_ex(tok, -infinity , 10) ... OK: got object of type [double]: -Infinity
json_tokener_parse_ex(tok, -infinity , 10) ... OK: got correct error: unexpected character
json_tokener_parse_ex(tok, inf , 3) ... OK: got correct error: continue
json_tokener_parse_ex(tok, inity , 6) ... OK: got object of type [double]: Infinity
@@ -218,11 +220,14 @@ json_tokener_parse_ex(tok, [-9223372036854775809], 23) ... OK: got correct erro
json_tokener_parse_ex(tok, [18446744073709551615], 23) ... OK: got object of type [array]: [ 18446744073709551615 ]
json_tokener_parse_ex(tok, [18446744073709551616], 23) ... OK: got object of type [array]: [ 18446744073709551615 ]
json_tokener_parse_ex(tok, [18446744073709551616], 23) ... OK: got correct error: number expected
+json_tokener_parse_ex(tok, 18446744073709551616, 21) ... OK: got object of type [int]: 18446744073709551615
json_tokener_parse_ex(tok, 18446744073709551616, 21) ... OK: got correct error: unexpected end of data
json_tokener_parse_ex(tok, [9223372036854775808.0], 24) ... OK: got object of type [array]: [ 9223372036854775808.0 ]
json_tokener_parse_ex(tok, [-9223372036854775809.0], 25) ... OK: got object of type [array]: [ -9223372036854775809.0 ]
+json_tokener_parse_ex(tok, [-9223372036854775809.0], 25) ... OK: got object of type [array]: [ -9223372036854775809.0 ]
json_tokener_parse_ex(tok, [18446744073709551615.0], 25) ... OK: got object of type [array]: [ 18446744073709551615.0 ]
json_tokener_parse_ex(tok, [18446744073709551616.0], 25) ... OK: got object of type [array]: [ 18446744073709551616.0 ]
+json_tokener_parse_ex(tok, [18446744073709551616.0], 25) ... OK: got object of type [array]: [ 18446744073709551616.0 ]
json_tokener_parse_ex(tok, noodle , 7) ... OK: got correct error: null expected
json_tokener_parse_ex(tok, naodle , 7) ... OK: got correct error: null expected
json_tokener_parse_ex(tok, track , 6) ... OK: got correct error: boolean expected
@@ -250,6 +255,7 @@ json_tokener_parse_ex(tok, "\t" , 4) ... OK: got object of type [string
json_tokener_parse_ex(tok, "\/" , 4) ... OK: got object of type [string]: "\/"
json_tokener_parse_ex(tok, "/" , 3) ... OK: got object of type [string]: "\/"
json_tokener_parse_ex(tok, "\a" , 4) ... OK: got correct error: invalid string sequence
+json_tokener_parse_ex(tok, 'foo' , 5) ... OK: got object of type [string]: "foo"
json_tokener_parse_ex(tok, 'foo' , 5) ... OK: got correct error: unexpected character
json_tokener_parse_ex(tok, [1,2,3] , 7) ... OK: got object of type [array]: [ 1, 2, 3 ]
json_tokener_parse_ex(tok, [1,2,3} , 7) ... OK: got correct error: array value separator ',' expected
@@ -263,8 +269,9 @@ json_tokener_parse_ex(tok, {"a":1 , 6) ... OK: got correct error: continu
json_tokener_parse_ex(tok, [,] , 3) ... OK: got correct error: unexpected character
json_tokener_parse_ex(tok, [,1] , 4) ... OK: got correct error: unexpected character
json_tokener_parse_ex(tok, [1,2,3,] , 8) ... OK: got object of type [array]: [ 1, 2, 3 ]
-json_tokener_parse_ex(tok, [1,2,,3,] , 9) ... OK: got correct error: unexpected character
json_tokener_parse_ex(tok, [1,2,3,] , 8) ... OK: got correct error: unexpected character
+json_tokener_parse_ex(tok, [1,2,,3,] , 9) ... OK: got correct error: unexpected character
+json_tokener_parse_ex(tok, [1,2,,3,] , 9) ... OK: got correct error: unexpected character
json_tokener_parse_ex(tok, {"a":1,} , 8) ... OK: got correct error: unexpected character
json_tokener_parse_ex(tok, "123asc$%&" , 11) ... OK: got object of type [string]: "123asc$%&"
json_tokener_parse_ex(tok, "123asc$%&" , 11) ... OK: got object of type [string]: "123asc$%&"
@@ -322,5 +329,5 @@ json_tokener_parse_ex(tok, "" , 3) ... OK: got correct error: invalid
json_tokener_parse_ex(tok, "" , 3) ... OK: got correct error: invalid string sequence
json_tokener_parse_ex(tok, "" , 3) ... OK: got correct error: invalid string sequence
json_tokener_parse_ex(tok, "" , 3) ... OK: got correct error: invalid string sequence
-End Incremental Tests OK=230 ERROR=0
+End Incremental Tests OK=237 ERROR=0
==================================
--
2.43.0

View File

@ -0,0 +1,37 @@
From 474ee12435e671607c02f764b173258e3a059eda Mon Sep 17 00:00:00 2001
From: Eric Hawicz <erh+git@nimenees.com>
Date: Sun, 3 Nov 2024 19:44:21 -0500
Subject: [PATCH] Fix the apps/json_parse "-s" (strict) option so it actually
does something, and default to non-strict.
---
apps/json_parse.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/apps/json_parse.c b/apps/json_parse.c
index 31221d0..4eb629b 100644
--- a/apps/json_parse.c
+++ b/apps/json_parse.c
@@ -74,11 +74,14 @@ static int parseit(int fd, int (*callback)(struct json_object *))
fprintf(stderr, "unable to allocate json_tokener: %s\n", strerror(errno));
return 1;
}
- json_tokener_set_flags(tok, JSON_TOKENER_STRICT
-#ifdef JSON_TOKENER_ALLOW_TRAILING_CHARS
- | JSON_TOKENER_ALLOW_TRAILING_CHARS
-#endif
- );
+ if (strict_mode)
+ {
+ json_tokener_set_flags(tok, JSON_TOKENER_STRICT
+ #ifdef JSON_TOKENER_ALLOW_TRAILING_CHARS
+ | JSON_TOKENER_ALLOW_TRAILING_CHARS
+ #endif
+ );
+ }
// XXX push this into some kind of json_tokener_parse_fd API?
// json_object_from_fd isn't flexible enough, and mirroring
--
2.33.0

View File

@ -0,0 +1,57 @@
From 87900c0a2e688013d50326931eaa835b5a80f56b Mon Sep 17 00:00:00 2001
From: Eric Hawicz <erh+git@nimenees.com>
Date: Sun, 15 Sep 2024 11:59:05 -0400
Subject: [PATCH] Fix the expected output for test_parse
---
tests/test_parse.expected | 36 +++++++++++++++++++++++++++++++++++-
1 file changed, 35 insertions(+), 1 deletion(-)
diff --git a/tests/test_parse.expected b/tests/test_parse.expected
index 50fb6d8..82db5db 100644
--- a/tests/test_parse.expected
+++ b/tests/test_parse.expected
@@ -288,5 +288,39 @@ json_tokener_parse_ex(tok, "\ud855
json_tokener_parse_ex(tok, "\ud0031À" , 10) ... OK: got correct error: invalid utf-8 string
json_tokener_parse_ex(tok, 11<31>11 , 5) ... OK: got correct error: invalid utf-8 string
json_tokener_parse_ex(tok, {"1<>":1} , 8) ... OK: got correct error: invalid utf-8 string
-End Incremental Tests OK=198 ERROR=0
+json_tokener_parse_ex(tok, "0
+ ", 36) ... OK: got object of type [string]: "0\u0001\u0002\u0002\u0003\u0004\u0005\u0006\u0007\b\t\n\u000b\f\r\u000e\u000f\u0010\u0011\u0012\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f"
+json_tokener_parse_ex(tok, "" , 3) ... OK: got correct error: invalid string sequence
+json_tokener_parse_ex(tok, "" , 3) ... OK: got correct error: invalid string sequence
+json_tokener_parse_ex(tok, "" , 3) ... OK: got correct error: invalid string sequence
+json_tokener_parse_ex(tok, "" , 3) ... OK: got correct error: invalid string sequence
+json_tokener_parse_ex(tok, "" , 3) ... OK: got correct error: invalid string sequence
+json_tokener_parse_ex(tok, "" , 3) ... OK: got correct error: invalid string sequence
+json_tokener_parse_ex(tok, "" , 3) ... OK: got correct error: invalid string sequence
+json_tokener_parse_ex(tok, "" , 3) ... OK: got correct error: invalid string sequence
+json_tokener_parse_ex(tok, " " , 3) ... OK: got correct error: invalid string sequence
+json_tokener_parse_ex(tok, "
+" , 3) ... OK: got correct error: invalid string sequence
+json_tokener_parse_ex(tok, " " , 3) ... OK: got correct error: invalid string sequence
+json_tokener_parse_ex(tok, " " , 3) ... OK: got correct error: invalid string sequence
+json_tokener_parse_ex(tok, " " , 3) ... OK: got correct error: invalid string sequence
+json_tokener_parse_ex(tok, "" , 3) ... OK: got correct error: invalid string sequence
+json_tokener_parse_ex(tok, "" , 3) ... OK: got correct error: invalid string sequence
+json_tokener_parse_ex(tok, "" , 3) ... OK: got correct error: invalid string sequence
+json_tokener_parse_ex(tok, "" , 3) ... OK: got correct error: invalid string sequence
+json_tokener_parse_ex(tok, "" , 3) ... OK: got correct error: invalid string sequence
+json_tokener_parse_ex(tok, "" , 3) ... OK: got correct error: invalid string sequence
+json_tokener_parse_ex(tok, "" , 3) ... OK: got correct error: invalid string sequence
+json_tokener_parse_ex(tok, "" , 3) ... OK: got correct error: invalid string sequence
+json_tokener_parse_ex(tok, "" , 3) ... OK: got correct error: invalid string sequence
+json_tokener_parse_ex(tok, "" , 3) ... OK: got correct error: invalid string sequence
+json_tokener_parse_ex(tok, "" , 3) ... OK: got correct error: invalid string sequence
+json_tokener_parse_ex(tok, "" , 3) ... OK: got correct error: invalid string sequence
+json_tokener_parse_ex(tok, "" , 3) ... OK: got correct error: invalid string sequence
+json_tokener_parse_ex(tok, "" , 3) ... OK: got correct error: invalid string sequence
+json_tokener_parse_ex(tok, "" , 3) ... OK: got correct error: invalid string sequence
+json_tokener_parse_ex(tok, "" , 3) ... OK: got correct error: invalid string sequence
+json_tokener_parse_ex(tok, "" , 3) ... OK: got correct error: invalid string sequence
+json_tokener_parse_ex(tok, "" , 3) ... OK: got correct error: invalid string sequence
+End Incremental Tests OK=230 ERROR=0
==================================
--
2.43.0

View File

@ -0,0 +1,32 @@
From 828c12b22661de53d6497bd1410c68cb153b4f35 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A1n=20Tomko?= <jtomko@redhat.com>
Date: Wed, 6 Nov 2024 15:19:04 +0100
Subject: [PATCH] Handle NULL gracefully in json_tokener_free
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Similarly to glibc's free, make json_tokener_free(NULL)
a no-op, to simplify cleanup paths.
Signed-off-by: Ján Tomko <jtomko@redhat.com>
---
json_tokener.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/json_tokener.c b/json_tokener.c
index c831f8a..4453c89 100644
--- a/json_tokener.c
+++ b/json_tokener.c
@@ -182,6 +182,8 @@ struct json_tokener *json_tokener_new(void)
void json_tokener_free(struct json_tokener *tok)
{
+ if (!tok)
+ return;
json_tokener_reset(tok);
if (tok->pb)
printbuf_free(tok->pb);
--
2.35.1.windows.2

View File

@ -0,0 +1,31 @@
From 833233faa8d6835276ebbd48b92c7feeb141270d Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Mon, 22 Apr 2024 01:50:59 +0200
Subject: [PATCH] Handle yet another out-of-memory condition.
duplocale() can return NULL, with errno set to ENOMEM.
In this case, bail out and set the current error code to
json_tokener_error_memory.
---
json_tokener.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/json_tokener.c b/json_tokener.c
index cc35527..0a86d82 100644
--- a/json_tokener.c
+++ b/json_tokener.c
@@ -341,6 +341,11 @@ struct json_object *json_tokener_parse_ex(struct json_tokener *tok, const char *
#ifdef HAVE_USELOCALE
{
locale_t duploc = duplocale(oldlocale);
+ if (duploc == NULL && errno == ENOMEM)
+ {
+ tok->err = json_tokener_error_memory;
+ return NULL;
+ }
newloc = newlocale(LC_NUMERIC_MASK, "C", duploc);
if (newloc == NULL)
{
--
2.43.4

View File

@ -0,0 +1,49 @@
From 31a22fb2dabae30a759ae3346b493b44cedf1647 Mon Sep 17 00:00:00 2001
From: Eric Hawicz <erh+git@nimenees.com>
Date: Sun, 21 Apr 2024 10:37:16 -0400
Subject: [PATCH] Issue #857: fix a few places where json_tokener should have
been returning json_tokener_error_memory but wasn't.
---
json_tokener.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/json_tokener.c b/json_tokener.c
index e8244a3..cc35527 100644
--- a/json_tokener.c
+++ b/json_tokener.c
@@ -344,6 +344,7 @@ struct json_object *json_tokener_parse_ex(struct json_tokener *tok, const char *
newloc = newlocale(LC_NUMERIC_MASK, "C", duploc);
if (newloc == NULL)
{
+ tok->err = json_tokener_error_memory;
freelocale(duploc);
return NULL;
}
@@ -362,7 +363,10 @@ struct json_object *json_tokener_parse_ex(struct json_tokener *tok, const char *
{
oldlocale = strdup(tmplocale);
if (oldlocale == NULL)
+ {
+ tok->err = json_tokener_error_memory;
return NULL;
+ }
}
setlocale(LC_NUMERIC, "C");
}
@@ -1257,7 +1261,11 @@ struct json_object *json_tokener_parse_ex(struct json_tokener *tok, const char *
goto redo_char;
case json_tokener_state_object_value_add:
- json_object_object_add(current, obj_field_name, obj);
+ if (json_object_object_add(current, obj_field_name, obj) != 0)
+ {
+ tok->err = json_tokener_error_memory;
+ goto out;
+ }
free(obj_field_name);
obj_field_name = NULL;
saved_state = json_tokener_state_object_sep;
--
2.43.4

View File

@ -0,0 +1,88 @@
From 6bfab90c87c27e79eae28b775938756d2fdaf6c9 Mon Sep 17 00:00:00 2001
From: Eric Hawicz <erh+git@nimenees.com>
Date: Mon, 2 Sep 2024 09:43:04 -0400
Subject: [PATCH] Issue #867: disallow control characters in strict mode.
---
json_tokener.c | 6 ++++++
tests/test_parse.c | 40 +++++++++++++++++++++++++++++++++++++++-
2 files changed, 45 insertions(+), 1 deletion(-)
diff --git a/json_tokener.c b/json_tokener.c
index 0a86d82..c831f8a 100644
--- a/json_tokener.c
+++ b/json_tokener.c
@@ -678,6 +678,12 @@ struct json_object *json_tokener_parse_ex(struct json_tokener *tok, const char *
state = json_tokener_state_string_escape;
break;
}
+ else if ((tok->flags & JSON_TOKENER_STRICT) && c <= 0x1f)
+ {
+ // Disallow control characters in strict mode
+ tok->err = json_tokener_error_parse_string;
+ goto out;
+ }
if (!ADVANCE_CHAR(str, tok) || !PEEK_CHAR(c, tok))
{
printbuf_memappend_checked(tok->pb, case_start,
diff --git a/tests/test_parse.c b/tests/test_parse.c
index 92d822a..d664a31 100644
--- a/tests/test_parse.c
+++ b/tests/test_parse.c
@@ -535,7 +535,7 @@ struct incremental_step
{"{\"a\":}", -1, 5, json_tokener_error_parse_unexpected, 1, 0},
{"{\"a\":1,\"a\":2}", -1, -1, json_tokener_success, 1, 0},
{"\"a\":1}", -1, 3, json_tokener_success, 1, 0},
- {"{\"a\":1", -1, -1, json_tokener_continue, 1, 0},
+ {"{\"a\":1", -1, -1, json_tokener_continue, 1, 0}, //}
{"[,]", -1, 1, json_tokener_error_parse_unexpected, 1, 0},
{"[,1]", -1, 1, json_tokener_error_parse_unexpected, 1, 0},
@@ -595,6 +595,44 @@ struct incremental_step
{"\x7b\x22\x31\x81\x22\x3a\x31\x7d", -1, 3, json_tokener_error_parse_utf8_string, 1,
JSON_TOKENER_VALIDATE_UTF8},
+ // Note, current asciiz APIs can't parse \x00, skip it
+ { "\"0\x01\x02\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f" \
+ "\x10\x11\x12\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\"",
+ -1, -1, json_tokener_success, 1, 0 },
+
+ // Test control chars again, this time in strict mode, which should fail
+ { "\"\x01\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
+ { "\"\x02\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
+ { "\"\x03\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
+ { "\"\x04\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
+ { "\"\x05\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
+ { "\"\x06\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
+ { "\"\x07\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
+ { "\"\x08\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
+ { "\"\x09\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
+ { "\"\x0a\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
+ { "\"\x0b\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
+ { "\"\x0c\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
+ { "\"\x0d\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
+ { "\"\x0e\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
+ { "\"\x0f\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
+ { "\"\x10\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
+ { "\"\x11\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
+ { "\"\x12\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
+ { "\"\x13\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
+ { "\"\x14\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
+ { "\"\x15\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
+ { "\"\x16\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
+ { "\"\x17\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
+ { "\"\x18\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
+ { "\"\x19\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
+ { "\"\x1a\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
+ { "\"\x1b\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
+ { "\"\x1c\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
+ { "\"\x1d\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
+ { "\"\x1e\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
+ { "\"\x1f\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
+
{NULL, -1, -1, json_tokener_success, 0, 0},
};
--
2.43.0

View File

@ -0,0 +1,40 @@
From ff8ed0f094ddb48edad8169b711097f69fe8efea Mon Sep 17 00:00:00 2001
From: Eric Hawicz <erh+git@nimenees.com>
Date: Sun, 17 Nov 2024 22:11:24 -0500
Subject: [PATCH] Issue #881: don't allow json_tokener_new_ex() with a depth <
1
---
json_tokener.c | 3 +++
json_tokener.h | 1 +
2 files changed, 4 insertions(+)
diff --git a/json_tokener.c b/json_tokener.c
index 773229e..1954bcd 100644
--- a/json_tokener.c
+++ b/json_tokener.c
@@ -154,6 +154,9 @@ struct json_tokener *json_tokener_new_ex(int depth)
{
struct json_tokener *tok;
+ if (depth < 1)
+ return NULL;
+
tok = (struct json_tokener *)calloc(1, sizeof(struct json_tokener));
if (!tok)
return NULL;
diff --git a/json_tokener.h b/json_tokener.h
index 54925e5..f53a761 100644
--- a/json_tokener.h
+++ b/json_tokener.h
@@ -206,6 +206,7 @@ JSON_EXPORT struct json_tokener *json_tokener_new(void);
/**
* Allocate a new json_tokener with a custom max nesting depth.
+ * The depth must be at least 1.
* @see JSON_TOKENER_DEFAULT_DEPTH
*/
JSON_EXPORT struct json_tokener *json_tokener_new_ex(int depth);
--
2.35.1.windows.2

View File

@ -0,0 +1,31 @@
From ad8b8afa7d567053b87f2d37ee4a534e13c210c7 Mon Sep 17 00:00:00 2001
From: Eric Hawicz <erh+git@nimenees.com>
Date: Fri, 22 Sep 2023 22:26:21 -0400
Subject: [PATCH] Take 2 fixing the placement of json_tokener_error_memory in
the enum. (json_tokener_error_size is an actual error, *not* a measure of
the size of the enum!)
Reference:https://github.com/json-c/json-c/commit/ad8b8afa7d567053b87f2d37ee4a534e13c210c7
Conflict:NA
---
json_tokener.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/json_tokener.h b/json_tokener.h
index 77abc5c18d..cdac3e2afe 100644
--- a/json_tokener.h
+++ b/json_tokener.h
@@ -40,8 +40,8 @@ enum json_tokener_error
json_tokener_error_parse_string,
json_tokener_error_parse_comment,
json_tokener_error_parse_utf8_string,
- json_tokener_error_memory,
- json_tokener_error_size
+ json_tokener_error_size, /* A string longer than INT32_MAX was passed as input */
+ json_tokener_error_memory /* Failed to allocate memory */
};
/**
--
2.43.4

View File

@ -6,7 +6,7 @@
Name: json-c
Version: 0.17
Release: 2
Release: 7
Summary: JSON implementation in C
License: MIT
@ -15,7 +15,17 @@ Source0: %{url}/archive/%{name}-%{version}-%{reldate}.tar.gz
BuildRequires: cmake gcc ninja-build
Patch001: backport-fix-issue-854-Set-error-json_tokener_error_memory-in.patch
Patch6001: backport-fix-issue-854-Set-error-json_tokener_error_memory-in.patch
Patch6002: backport-Handle-yet-another-out-of-memory-condition.patch
Patch6003: backport-Issue-857-fix-a-few-places-where-json_tokener-should.patch
Patch6004: backport-Take-2-fixing-the-placement-of-json_tokener_error_memory.patch
Patch6005: backport-Issue-867-disallow-control-characters-in-strict-mode.patch
Patch6006: backport-Fix-the-expected-output-for-test_parse.patch
Patch6007: backport-Fix-issue-875-cast-to-unsigned-char-so-bytes-above-0.patch
Patch6008: backport-Fix-the-apps-json_parse-s-strict-option-so-it-actual.patch
Patch6009: backport-Handle-NULL-gracefully-in-json_tokener_free.patch
Patch6010: backport-Issue-881-don-t-allow-json_tokener_new_ex-with-a-dep.patch
%description
JSON-C implements a reference counting object model that allows you
@ -103,6 +113,34 @@ end
%doc %{_pkgdocdir}
%changelog
* Sat Mar 15 2025 sunhai <sunhai10@huawei.com> - 0.17-7
- Type:bugfix
- ID:NA
- SUG:NA
- DESC: Handle NULL gracefully in json_tokener_free
Issue 881 don t allow json_tokener_new_ex with a dep
* Fri Dec 06 2024 sunhai <sunhai10@huawei.com> - 0.17-6
- Type:bugfix
- ID:NA
- SUG:NA
- DESC: Fix the apps/json_parse "-s" (strict) option so it actually does something, and default to non-strict.
* Wed Dec 04 2024 yueyuankun <yueyuankun@kylinos.cn> - 0.17-5
- Type:bugfix
- ID:NA
- SUG:NA
- DESC: Disallow control characters in strict mode
Fix the expected output for test_parse
Fix causing the strict-mode control characters check to incorrectly trigger
* Tue Sep 24 2024 sunhai <sunhai10@huawei.com> - 0.17-4
- Take 2 fixing the placement of json_tokener_error_memory in the enum.
* Mon Jun 24 2024 liweigang <liweiganga@uniontech.com> - 0.17-3
- add backport-Handle-yet-another-out-of-memory-condition.patch
- add backport-Issue-857-fix-a-few-places-where-json_tokener-should.patch
* Thu May 16 2024 xiaozai <xiaozai@kylinos.cn> - 0.17-2
- add backport-fix-issue-854-Set-error-json_tokener_error_memory-in.patch