diff --git a/backport-Handle-yet-another-out-of-memory-condition.patch b/backport-Handle-yet-another-out-of-memory-condition.patch new file mode 100644 index 0000000000000000000000000000000000000000..c32bff311cffcc1e6536d163c71f74f2474e4084 --- /dev/null +++ b/backport-Handle-yet-another-out-of-memory-condition.patch @@ -0,0 +1,31 @@ +From 833233faa8d6835276ebbd48b92c7feeb141270d Mon Sep 17 00:00:00 2001 +From: Bruno Haible +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 + diff --git a/backport-Issue-857-fix-a-few-places-where-json_tokener-should.patch b/backport-Issue-857-fix-a-few-places-where-json_tokener-should.patch new file mode 100644 index 0000000000000000000000000000000000000000..0356d95b418f282533bb9056b58769aed22ccd34 --- /dev/null +++ b/backport-Issue-857-fix-a-few-places-where-json_tokener-should.patch @@ -0,0 +1,49 @@ +From 31a22fb2dabae30a759ae3346b493b44cedf1647 Mon Sep 17 00:00:00 2001 +From: Eric Hawicz +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 + diff --git a/backport-Take-2-fixing-the-placement-of-json_tokener_error_memory.patch b/backport-Take-2-fixing-the-placement-of-json_tokener_error_memory.patch new file mode 100644 index 0000000000000000000000000000000000000000..5a4b2612b00466d1bcbe70f29252a8898c433e41 --- /dev/null +++ b/backport-Take-2-fixing-the-placement-of-json_tokener_error_memory.patch @@ -0,0 +1,31 @@ +From ad8b8afa7d567053b87f2d37ee4a534e13c210c7 Mon Sep 17 00:00:00 2001 +From: Eric Hawicz +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 \ No newline at end of file diff --git a/backport-fix-issue-854-Set-error-json_tokener_error_memory-in.patch b/backport-fix-issue-854-Set-error-json_tokener_error_memory-in.patch new file mode 100644 index 0000000000000000000000000000000000000000..925d6a94233bb1298e45f25a617b47d6cf751f96 --- /dev/null +++ b/backport-fix-issue-854-Set-error-json_tokener_error_memory-in.patch @@ -0,0 +1,28 @@ +From e93ae70417867dac9ff87614f3e7bc50e79ef951 Mon Sep 17 00:00:00 2001 +From: Eric Hawicz +Date: Fri, 29 Mar 2024 18:09:12 -0400 +Subject: [PATCH 093/100] Fix issue #854: Set error=json_tokener_error_memory + in json_tokener_parser_verbose() when allocating the tokener fails. + +--- + json_tokener.c | 3 +++ + 1 file changed, 3 insertions(+) + +diff --git a/json_tokener.c b/json_tokener.c +index 9926563..e8244a3 100644 +--- a/json_tokener.c ++++ b/json_tokener.c +@@ -226,7 +226,10 @@ struct json_object *json_tokener_parse_verbose(const char *str, enum json_tokene + + tok = json_tokener_new(); + if (!tok) ++ { ++ *error = json_tokener_error_memory; + return NULL; ++ } + obj = json_tokener_parse_ex(tok, str, -1); + *error = tok->err; + if (tok->err != json_tokener_success +-- +2.33.0 + diff --git a/json-c.spec b/json-c.spec index a48a6860cb0d05ce06a16d6135572c41e826b7c7..abaa63a8c09456a185fdb58218c01b48f5ca5873 100644 --- a/json-c.spec +++ b/json-c.spec @@ -6,7 +6,7 @@ Name: json-c Version: 0.17 -Release: 1 +Release: 4 Summary: JSON implementation in C License: MIT @@ -15,6 +15,11 @@ 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 +Patch002: backport-Handle-yet-another-out-of-memory-condition.patch +Patch003: backport-Issue-857-fix-a-few-places-where-json_tokener-should.patch +Patch004: backport-Take-2-fixing-the-placement-of-json_tokener_error_memory.patch + %description JSON-C implements a reference counting object model that allows you to easily construct JSON objects in C, output them as JSON formatted @@ -101,6 +106,16 @@ end %doc %{_pkgdocdir} %changelog +* Tue Sep 24 2024 sunhai - 0.17-4 +- Take 2 fixing the placement of json_tokener_error_memory in the enum. + +* Mon Jun 24 2024 liweigang - 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 - 0.17-2 +- add backport-fix-issue-854-Set-error-json_tokener_error_memory-in.patch + * Wed Aug 16 2023 dillon chen - 0.17-1 - Update to 0.17