teknoraver / rpms / systemd

Forked from rpms/systemd 2 months ago
Clone

Blame SOURCES/0222-sd-bus-make-strict-asan-shut-up.patch

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