json-c/backport-Issue-857-fix-a-few-places-where-json_tokener-should.patch
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

50 lines
1.5 KiB
Diff

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