mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-08 21:17:47 +03:00
coredump: when parsing json, optionally copy the string first
(cherry picked from commit 87707784c7
)
This commit is contained in:
parent
de08edca17
commit
344efd022a
@ -328,6 +328,19 @@ static int parse_package_metadata(const char *name, JsonVariant *id_json, Elf *e
|
||||
if (note_header.n_type != ELF_PACKAGE_METADATA_ID)
|
||||
continue;
|
||||
|
||||
_cleanup_free_ char *payload_0suffixed = NULL;
|
||||
assert(note_offset > desc_offset);
|
||||
size_t payload_len = note_offset - desc_offset;
|
||||
|
||||
/* If we are lucky and the payload is NUL-padded, we don't need to copy the string.
|
||||
* But if happens to go all the way until the end of the buffer, make a copy. */
|
||||
if (payload[payload_len-1] != '\0') {
|
||||
payload_0suffixed = memdup_suffix0(payload, payload_len);
|
||||
if (!payload_0suffixed)
|
||||
return log_oom();
|
||||
payload = payload_0suffixed;
|
||||
}
|
||||
|
||||
r = json_parse(payload, 0, &v, NULL, NULL);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "json_parse on %s failed: %m", payload);
|
||||
|
Loading…
Reference in New Issue
Block a user