1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-25 10:04:04 +03:00

json: add trailing NUL byte in json_dispatch_byte_array_iovec()

For safety.

Addresses https://github.com/systemd/systemd/pull/30879#discussion_r1448518226.
This commit is contained in:
Yu Watanabe 2024-01-12 04:44:48 +09:00
parent 378712c830
commit 1f179b37f2

View File

@ -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.");
@ -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;