Skip to content

Commit

Permalink
json: add trailing NUL byte in json_dispatch_byte_array_iovec()
Browse files Browse the repository at this point in the history
For safety.

Addresses #30879 (comment).
  • Loading branch information
yuwata authored and pull[bot] committed Feb 23, 2024
1 parent 135afc9 commit 1000000
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/shared/json.c
Expand Up @@ -5007,7 +5007,7 @@ int json_dispatch_byte_array_iovec(const char *name, JsonVariant *variant, JsonD

sz = json_variant_elements(variant);

buffer = new(uint8_t, sz);
buffer = new(uint8_t, sz + 1);
if (!buffer)
return json_log(variant, flags, SYNTHETIC_ERRNO(ENOMEM), "Out of memory.");

Expand All @@ -5028,6 +5028,9 @@ int json_dispatch_byte_array_iovec(const char *name, JsonVariant *variant, JsonD
}
assert(k == sz);

/* Append a NUL byte for safety, like we do in memdup_suffix0() and others. */
buffer[sz] = 0;

free_and_replace(iov->iov_base, buffer);
iov->iov_len = sz;
return 0;
Expand Down

0 comments on commit 1000000

Please sign in to comment.