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
This commit is contained in:
Lennart Poettering 2018-11-16 13:00:40 +01:00
parent 62adb5d085
commit ac0a94f743

View file

@ -4057,7 +4057,7 @@ _public_ int sd_bus_message_enter_container(sd_bus_message *m,
end = m->rindex + 0;
else
end = m->rindex + c->item_size;
m->containers[m->n_containers++] = (struct bus_container) {
.enclosing = type,
.signature = TAKE_PTR(signature),
@ -5078,6 +5078,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
@ -5091,9 +5092,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;
}