mirror of https://github.com/asterisk/asterisk
Use json_vsprintf from versions which contain fix for va_copy leak. Apply fixes from jansson master: * va_copy leak fix. * Avoid potential invalid memory read in json_pack. * Rename variable that shadowed another. Change-Id: I7522e462d2a52f53010ffa1e7d705c666ec3553916.1
parent
3ddfeccf35
commit
ede59966d9
@ -0,0 +1,38 @@
|
||||
From aed855e6920923898b94a1b922fbace27a34ddf2 Mon Sep 17 00:00:00 2001
|
||||
From: Petri Lehtinen <petri@digip.org>
|
||||
Date: Mon, 9 Jul 2018 22:26:35 +0300
|
||||
Subject: [PATCH 22/29] Avoid invalid memory read in json_pack()
|
||||
|
||||
Initial patch by @bharjoc-bitdefender
|
||||
|
||||
Fixes #421
|
||||
---
|
||||
src/pack_unpack.c | 5 ++++-
|
||||
1 file changed, 4 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/src/pack_unpack.c b/src/pack_unpack.c
|
||||
index 6461c06..b842772 100644
|
||||
--- a/src/pack_unpack.c
|
||||
+++ b/src/pack_unpack.c
|
||||
@@ -75,6 +75,9 @@ static void next_token(scanner_t *s)
|
||||
return;
|
||||
}
|
||||
|
||||
+ if (!token(s) && !*s->fmt)
|
||||
+ return;
|
||||
+
|
||||
t = s->fmt;
|
||||
s->column++;
|
||||
s->pos++;
|
||||
@@ -97,7 +100,7 @@ static void next_token(scanner_t *s)
|
||||
s->token.column = s->column;
|
||||
s->token.pos = s->pos;
|
||||
|
||||
- t++;
|
||||
+ if (*t) t++;
|
||||
s->fmt = t;
|
||||
}
|
||||
|
||||
--
|
||||
2.17.1
|
||||
|
@ -0,0 +1,64 @@
|
||||
From 66e4ee795d21a30118f8503c966e9f9ae87db315 Mon Sep 17 00:00:00 2001
|
||||
From: Xin Long <lucien.xin@gmail.com>
|
||||
Date: Wed, 25 Jul 2018 17:39:33 +0800
|
||||
Subject: [PATCH 25/29] Call va_end after va_copy in json_vsprintf
|
||||
|
||||
As said in man doc:
|
||||
"Each invocation of va_copy() must be matched by a corresponding
|
||||
invocation of va_end() in the same function."
|
||||
|
||||
va_copy may alloc memory in some system, it's necessay to free it by
|
||||
va_end.
|
||||
|
||||
Fixes: efe6c7b3f2b3 ("Add json_sprintf and json_vsprintf")
|
||||
Signed-off-by: Xin Long <lucien.xin@gmail.com>
|
||||
---
|
||||
src/value.c | 17 ++++++++++++-----
|
||||
1 file changed, 12 insertions(+), 5 deletions(-)
|
||||
|
||||
diff --git a/src/value.c b/src/value.c
|
||||
index 29a978c..861dce8 100644
|
||||
--- a/src/value.c
|
||||
+++ b/src/value.c
|
||||
@@ -781,26 +781,33 @@ static json_t *json_string_copy(const json_t *string)
|
||||
}
|
||||
|
||||
json_t *json_vsprintf(const char *fmt, va_list ap) {
|
||||
+ json_t *json = NULL;
|
||||
int length;
|
||||
char *buf;
|
||||
va_list aq;
|
||||
va_copy(aq, ap);
|
||||
|
||||
length = vsnprintf(NULL, 0, fmt, ap);
|
||||
- if (length == 0)
|
||||
- return json_string("");
|
||||
+ if (length == 0) {
|
||||
+ json = json_string("");
|
||||
+ goto out;
|
||||
+ }
|
||||
|
||||
buf = jsonp_malloc(length + 1);
|
||||
if (!buf)
|
||||
- return NULL;
|
||||
+ goto out;
|
||||
|
||||
vsnprintf(buf, length + 1, fmt, aq);
|
||||
if (!utf8_check_string(buf, length)) {
|
||||
jsonp_free(buf);
|
||||
- return NULL;
|
||||
+ goto out;
|
||||
}
|
||||
|
||||
- return jsonp_stringn_nocheck_own(buf, length);
|
||||
+ json = jsonp_stringn_nocheck_own(buf, length);
|
||||
+
|
||||
+out:
|
||||
+ va_end(aq);
|
||||
+ return json;
|
||||
}
|
||||
|
||||
json_t *json_sprintf(const char *fmt, ...) {
|
||||
--
|
||||
2.17.1
|
||||
|
@ -0,0 +1,56 @@
|
||||
From 020cc26b5cb147ae3569a3f7d314d3900b4bbc0b Mon Sep 17 00:00:00 2001
|
||||
From: Petri Lehtinen <petri@digip.org>
|
||||
Date: Sun, 12 Aug 2018 18:25:51 +0300
|
||||
Subject: [PATCH 27/29] Rename a varialble that shadows another one
|
||||
|
||||
configure.ac changes are removed for bundled jansson.
|
||||
|
||||
Fixes #430
|
||||
---
|
||||
configure.ac | 2 +-
|
||||
src/dump.c | 8 ++++----
|
||||
2 files changed, 5 insertions(+), 5 deletions(-)
|
||||
|
||||
diff --git a/src/dump.c b/src/dump.c
|
||||
index 8e725c9..4a64aa4 100644
|
||||
--- a/src/dump.c
|
||||
+++ b/src/dump.c
|
||||
@@ -306,7 +306,7 @@ static int do_dump(const json_t *json, size_t flags, int depth,
|
||||
const char *separator;
|
||||
int separator_length;
|
||||
/* Space for "0x", double the sizeof a pointer for the hex and a terminator. */
|
||||
- char key[2 + (sizeof(json) * 2) + 1];
|
||||
+ char loop_key[2 + (sizeof(json) * 2) + 1];
|
||||
|
||||
if(flags & JSON_COMPACT) {
|
||||
separator = ":";
|
||||
@@ -318,7 +318,7 @@ static int do_dump(const json_t *json, size_t flags, int depth,
|
||||
}
|
||||
|
||||
/* detect circular references */
|
||||
- if (loop_check(parents, json, key, sizeof(key)))
|
||||
+ if (loop_check(parents, json, loop_key, sizeof(loop_key)))
|
||||
return -1;
|
||||
|
||||
iter = json_object_iter((json_t *)json);
|
||||
@@ -326,7 +326,7 @@ static int do_dump(const json_t *json, size_t flags, int depth,
|
||||
if(!embed && dump("{", 1, data))
|
||||
return -1;
|
||||
if(!iter) {
|
||||
- hashtable_del(parents, key);
|
||||
+ hashtable_del(parents, loop_key);
|
||||
return embed ? 0 : dump("}", 1, data);
|
||||
}
|
||||
if(dump_indent(flags, depth + 1, 0, dump, data))
|
||||
@@ -422,7 +422,7 @@ static int do_dump(const json_t *json, size_t flags, int depth,
|
||||
}
|
||||
}
|
||||
|
||||
- hashtable_del(parents, key);
|
||||
+ hashtable_del(parents, loop_key);
|
||||
return embed ? 0 : dump("}", 1, data);
|
||||
}
|
||||
|
||||
--
|
||||
2.17.1
|
||||
|
Loading…
Reference in new issue