backport upstream patch

Signed-off-by: liweigang <liweiganga@uniontech.com>
(cherry picked from commit b09a490c6fbcdc3e5a0c2f297f604c44a41e0664)
This commit is contained in:
liweigang 2024-06-24 13:44:56 +08:00 committed by openeuler-sync-bot
parent 5367af64bb
commit 94a82016bb
3 changed files with 87 additions and 1 deletions

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

@ -6,7 +6,7 @@
Name: json-c Name: json-c
Version: 0.17 Version: 0.17
Release: 2 Release: 3
Summary: JSON implementation in C Summary: JSON implementation in C
License: MIT License: MIT
@ -16,6 +16,8 @@ Source0: %{url}/archive/%{name}-%{version}-%{reldate}.tar.gz
BuildRequires: cmake gcc ninja-build BuildRequires: cmake gcc ninja-build
Patch001: backport-fix-issue-854-Set-error-json_tokener_error_memory-in.patch 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 %description
JSON-C implements a reference counting object model that allows you JSON-C implements a reference counting object model that allows you
@ -103,6 +105,10 @@ end
%doc %{_pkgdocdir} %doc %{_pkgdocdir}
%changelog %changelog
* 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 * Thu May 16 2024 xiaozai <xiaozai@kylinos.cn> - 0.17-2
- add backport-fix-issue-854-Set-error-json_tokener_error_memory-in.patch - add backport-fix-issue-854-Set-error-json_tokener_error_memory-in.patch