Merge pull request #537 from stoeckmann/vsnprintf

Handle vsnprintf corner cases.
This commit is contained in:
Petri Lehtinen 2020-05-23 20:42:25 +03:00 committed by GitHub
commit 52dfc3dd4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -797,16 +797,18 @@ json_t *json_vsprintf(const char *fmt, va_list ap) {
va_copy(aq, ap);
length = vsnprintf(NULL, 0, fmt, ap);
if (length < 0)
goto out;
if (length == 0) {
json = json_string("");
goto out;
}
buf = jsonp_malloc(length + 1);
buf = jsonp_malloc((size_t)length + 1);
if (!buf)
goto out;
vsnprintf(buf, length + 1, fmt, aq);
vsnprintf(buf, (size_t)length + 1, fmt, aq);
if (!utf8_check_string(buf, length)) {
jsonp_free(buf);
goto out;