valeriyvdovin / rpms / systemd

Forked from rpms/systemd 4 years ago
Clone

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

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