richardphibel / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
c62b8e
From 0045159ffd9fb174b3da5fcccb5d2139245fe089 Mon Sep 17 00:00:00 2001
c62b8e
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
c62b8e
Date: Mon, 9 Jul 2018 13:21:44 +0200
c62b8e
Subject: [PATCH] bus-message: do not crash on message with a string of zero
c62b8e
 length
c62b8e
c62b8e
We'd calculate the "real" length of the string as 'item_size - 1', which does
c62b8e
not work out well when item_size == 0.
c62b8e
c62b8e
(cherry-picked from commit 81b6e63029eefcb0ec03a3a7c248490e38106073)
c62b8e
c62b8e
Resolves: #1643396
c62b8e
---
c62b8e
 src/libsystemd/sd-bus/bus-message.c                |   6 ++++++
c62b8e
 .../crash-29ed3c202e0ffade3cad42c8bbeb6cc68a21eb8e | Bin 0 -> 51 bytes
c62b8e
 2 files changed, 6 insertions(+)
c62b8e
 create mode 100644 test/fuzz/fuzz-bus-message/crash-29ed3c202e0ffade3cad42c8bbeb6cc68a21eb8e
c62b8e
c62b8e
diff --git a/src/libsystemd/sd-bus/bus-message.c b/src/libsystemd/sd-bus/bus-message.c
c62b8e
index c8402a23a9..121e65674d 100644
c62b8e
--- a/src/libsystemd/sd-bus/bus-message.c
c62b8e
+++ b/src/libsystemd/sd-bus/bus-message.c
c62b8e
@@ -3402,6 +3402,12 @@ _public_ int sd_bus_message_read_basic(sd_bus_message *m, char type, void *p) {
c62b8e
                 if (IN_SET(type, SD_BUS_TYPE_STRING, SD_BUS_TYPE_OBJECT_PATH, SD_BUS_TYPE_SIGNATURE)) {
c62b8e
                         bool ok;
c62b8e
 
c62b8e
+                        /* D-Bus spec: The marshalling formats for the string-like types all end
c62b8e
+                         * with a single zero (NUL) byte, but that byte is not considered to be part
c62b8e
+                         * of the text. */
c62b8e
+                        if (c->item_size == 0)
c62b8e
+                                return -EBADMSG;
c62b8e
+
c62b8e
                         r = message_peek_body(m, &rindex, 1, c->item_size, &q);
c62b8e
                         if (r < 0)
c62b8e
                                 return r;
c62b8e
diff --git a/test/fuzz/fuzz-bus-message/crash-29ed3c202e0ffade3cad42c8bbeb6cc68a21eb8e b/test/fuzz/fuzz-bus-message/crash-29ed3c202e0ffade3cad42c8bbeb6cc68a21eb8e
c62b8e
new file mode 100644
c62b8e
index 0000000000000000000000000000000000000000..4488f0a6c685b5d43eddbe41a0c6a3b6be9b02e2
c62b8e
GIT binary patch
c62b8e
literal 51
c62b8e
fcmc~1WMC4sJpJnr13KV`0|t%6q+%$@&=ddw)CUPg
c62b8e
c62b8e
literal 0
c62b8e
HcmV?d00001
c62b8e