mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-05 20:20:07 +00:00
Merge "jansson: Backport fixes to bundled, use json_vsprintf if available." into 13
This commit is contained in:
3
configure
vendored
3
configure
vendored
@@ -9307,6 +9307,9 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
|
|||||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
|
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
|
||||||
$as_echo "yes" >&6; }
|
$as_echo "yes" >&6; }
|
||||||
|
|
||||||
|
$as_echo "#define HAVE_JANSSON_BUNDLED 1" >>confdefs.h
|
||||||
|
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
@@ -389,6 +389,9 @@
|
|||||||
/* Define if your system has the JANSSON libraries. */
|
/* Define if your system has the JANSSON libraries. */
|
||||||
#undef HAVE_JANSSON
|
#undef HAVE_JANSSON
|
||||||
|
|
||||||
|
/* Define if your system has JANSSON_BUNDLED */
|
||||||
|
#undef HAVE_JANSSON_BUNDLED
|
||||||
|
|
||||||
/* Define to 1 if you have the `kevent64' function. */
|
/* Define to 1 if you have the `kevent64' function. */
|
||||||
#undef HAVE_KEVENT64
|
#undef HAVE_KEVENT64
|
||||||
|
|
||||||
|
11
main/json.c
11
main/json.c
@@ -477,16 +477,25 @@ struct ast_json *ast_json_stringf(const char *format, ...)
|
|||||||
|
|
||||||
struct ast_json *ast_json_vstringf(const char *format, va_list args)
|
struct ast_json *ast_json_vstringf(const char *format, va_list args)
|
||||||
{
|
{
|
||||||
char *str = NULL;
|
|
||||||
json_t *ret = NULL;
|
json_t *ret = NULL;
|
||||||
|
|
||||||
if (format) {
|
if (format) {
|
||||||
|
/* json_pack was not introduced until jansson-2.0 so Asterisk could never
|
||||||
|
* be compiled against older versions. The version check can never match
|
||||||
|
* anything older than 2.12. */
|
||||||
|
#if defined(HAVE_JANSSON_BUNDLED) || JANSSON_MAJOR_VERSION > 2 || JANSSON_MINOR_VERSION > 11
|
||||||
|
ret = json_vsprintf(format, args);
|
||||||
|
#else
|
||||||
|
char *str = NULL;
|
||||||
int err = ast_vasprintf(&str, format, args);
|
int err = ast_vasprintf(&str, format, args);
|
||||||
|
|
||||||
if (err >= 0) {
|
if (err >= 0) {
|
||||||
ret = json_string(str);
|
ret = json_string(str);
|
||||||
ast_free(str);
|
ast_free(str);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
return (struct ast_json *)ret;
|
return (struct ast_json *)ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
1
third-party/jansson/configure.m4
vendored
1
third-party/jansson/configure.m4
vendored
@@ -82,6 +82,7 @@ AC_DEFUN([_JANSSON_CONFIGURE],
|
|||||||
AC_SUBST([JANSSON_LIB])
|
AC_SUBST([JANSSON_LIB])
|
||||||
AC_SUBST([JANSSON_INCLUDE])
|
AC_SUBST([JANSSON_INCLUDE])
|
||||||
AC_MSG_RESULT(yes)
|
AC_MSG_RESULT(yes)
|
||||||
|
AC_DEFINE([HAVE_JANSSON_BUNDLED], 1, [Define if your system has JANSSON_BUNDLED])
|
||||||
])
|
])
|
||||||
|
|
||||||
AC_DEFUN([JANSSON_CONFIGURE],
|
AC_DEFUN([JANSSON_CONFIGURE],
|
||||||
|
38
third-party/jansson/patches/0022-Avoid-invalid-memory-read-in-json_pack.patch
vendored
Normal file
38
third-party/jansson/patches/0022-Avoid-invalid-memory-read-in-json_pack.patch
vendored
Normal file
@@ -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
|
||||||
|
|
64
third-party/jansson/patches/0025-Call-va_end-after-va_copy-in-json_vsprintf.patch
vendored
Normal file
64
third-party/jansson/patches/0025-Call-va_end-after-va_copy-in-json_vsprintf.patch
vendored
Normal file
@@ -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
|
||||||
|
|
56
third-party/jansson/patches/0027-Rename-a-varialble-that-shadows-another-one.patch
vendored
Normal file
56
third-party/jansson/patches/0027-Rename-a-varialble-that-shadows-another-one.patch
vendored
Normal file
@@ -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
|
||||||
|
|
Reference in New Issue
Block a user