ryantimwilson / rpms / systemd

Forked from rpms/systemd a month ago
Clone
b9a53a
From fbe5fa22f5b99d4e444db54aadb661e9c932eb6c Mon Sep 17 00:00:00 2001
b9a53a
From: Lennart Poettering <lennart@poettering.net>
b9a53a
Date: Fri, 16 Nov 2018 13:00:40 +0100
b9a53a
Subject: [PATCH] sd-bus: make strict asan shut up
b9a53a
b9a53a
asan doesn't like it if we use strndup() (i.e. a string function) on a
b9a53a
non-NULL terminated buffer (i.e. something that isn't really a string).
b9a53a
b9a53a
Let's hence use memdup_suffix0() instead of strndup(), which is more
b9a53a
appropriate for binary data that is to become a string.
b9a53a
b9a53a
Fixes: #10385
b9a53a
(cherry picked from commit ac0a94f7438b49a0890d9806db1fa211a5bca10a)
b9a53a
b9a53a
Resolves: #1761519
b9a53a
---
b9a53a
 src/libsystemd/sd-bus/bus-message.c | 7 +++++--
b9a53a
 1 file changed, 5 insertions(+), 2 deletions(-)
b9a53a
b9a53a
diff --git a/src/libsystemd/sd-bus/bus-message.c b/src/libsystemd/sd-bus/bus-message.c
b9a53a
index 53cbd675b7..19cb2b9a97 100644
b9a53a
--- a/src/libsystemd/sd-bus/bus-message.c
b9a53a
+++ b/src/libsystemd/sd-bus/bus-message.c
b9a53a
@@ -5101,6 +5101,7 @@ int bus_message_parse_fields(sd_bus_message *m) {
b9a53a
                                 return -EBADMSG;
b9a53a
 
b9a53a
                         if (*p == 0) {
b9a53a
+                                char *k;
b9a53a
                                 size_t l;
b9a53a
 
b9a53a
                                 /* We found the beginning of the signature
b9a53a
@@ -5114,9 +5115,11 @@ int bus_message_parse_fields(sd_bus_message *m) {
b9a53a
                                     p[1 + l - 1] != SD_BUS_TYPE_STRUCT_END)
b9a53a
                                         return -EBADMSG;
b9a53a
 
b9a53a
-                                if (free_and_strndup(&m->root_container.signature,
b9a53a
-                                                     p + 1 + 1, l - 2) < 0)
b9a53a
+                                k = memdup_suffix0(p + 1 + 1, l - 2);
b9a53a
+                                if (!k)
b9a53a
                                         return -ENOMEM;
b9a53a
+
b9a53a
+                                free_and_replace(m->root_container.signature, k);
b9a53a
                                 break;
b9a53a
                         }
b9a53a