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/json-c.spec b/json-c.spec index 2468912c39727c4e2ac1e62e06e255212bb639d6..a2ce3c1a84e04434677726c1a1be7626a27d3298 100644 --- a/json-c.spec +++ b/json-c.spec @@ -6,7 +6,7 @@ Name: json-c Version: 0.17 -Release: 2 +Release: 3 Summary: JSON implementation in C License: MIT @@ -16,6 +16,8 @@ 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 %description JSON-C implements a reference counting object model that allows you @@ -103,6 +105,10 @@ end %doc %{_pkgdocdir} %changelog +* 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