summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2018-11-16 13:00:40 +0100
committerThe Plumber <50238977+systemd-rhel-bot@users.noreply.github.com>2019-10-16 17:40:15 +0200
commitfbe5fa22f5b99d4e444db54aadb661e9c932eb6c (patch)
tree88c59b1e8b27f415e840cd5373019e4d70d2d5c5
parent8bd791fb3a8e85063e297204bdef8004aacd22b1 (diff)
downloadsystemd-fbe5fa22f5b99d4e444db54aadb661e9c932eb6c.tar.gz
sd-bus: make strict asan shut up
asan doesn't like it if we use strndup() (i.e. a string function) on a non-NULL terminated buffer (i.e. something that isn't really a string). Let's hence use memdup_suffix0() instead of strndup(), which is more appropriate for binary data that is to become a string. Fixes: #10385 (cherry picked from commit ac0a94f7438b49a0890d9806db1fa211a5bca10a) Resolves: #1761519
-rw-r--r--src/libsystemd/sd-bus/bus-message.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/libsystemd/sd-bus/bus-message.c b/src/libsystemd/sd-bus/bus-message.c
index 53cbd675b7..19cb2b9a97 100644
--- a/src/libsystemd/sd-bus/bus-message.c
+++ b/src/libsystemd/sd-bus/bus-message.c
@@ -5101,6 +5101,7 @@ int bus_message_parse_fields(sd_bus_message *m) {
return -EBADMSG;
if (*p == 0) {
+ char *k;
size_t l;
/* We found the beginning of the signature
@@ -5114,9 +5115,11 @@ int bus_message_parse_fields(sd_bus_message *m) {
p[1 + l - 1] != SD_BUS_TYPE_STRUCT_END)
return -EBADMSG;
- if (free_and_strndup(&m->root_container.signature,
- p + 1 + 1, l - 2) < 0)
+ k = memdup_suffix0(p + 1 + 1, l - 2);
+ if (!k)
return -ENOMEM;
+
+ free_and_replace(m->root_container.signature, k);
break;
}