jansson: Backport fixes to bundled, use json_vsprintf if available.

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: I7522e462d2a52f53010ffa1e7d705c666ec35539
This commit is contained in:
Corey Farrell
2018-07-16 23:55:02 -04:00
parent 6e1cf9de6b
commit adf539b2f0
8 changed files with 182 additions and 34 deletions

View File

@@ -292,16 +292,25 @@ struct ast_json *ast_json_stringf(const char *format, ...)
struct ast_json *ast_json_vstringf(const char *format, va_list args)
{
char *str = NULL;
json_t *ret = NULL;
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);
if (err >= 0) {
ret = json_string(str);
ast_free(str);
}
#endif
}
return (struct ast_json *)ret;
}