diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2022-09-19 11:29:56 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2022-09-28 09:38:13 +0200 |
commit | 87707784c70dc9894ec613df0a6e75e732a362a3 (patch) | |
tree | 03fd0f10c2a7e7d174b0346b8ac4ce852f3ecd09 /src/shared/elf-util.c | |
parent | Merge pull request #24691 from yuwata/udev-node-check-existence (diff) | |
download | systemd-87707784c70dc9894ec613df0a6e75e732a362a3.tar.xz systemd-87707784c70dc9894ec613df0a6e75e732a362a3.zip |
coredump: when parsing json, optionally copy the string first
Diffstat (limited to 'src/shared/elf-util.c')
-rw-r--r-- | src/shared/elf-util.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/shared/elf-util.c b/src/shared/elf-util.c index 3ba06c5290..ae4193cacf 100644 --- a/src/shared/elf-util.c +++ b/src/shared/elf-util.c @@ -326,6 +326,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); |