valeriyvdovin / rpms / systemd

Forked from rpms/systemd 4 years ago
Clone

Blame SOURCES/0025-bus-message-do-not-crash-on-message-with-a-string-of.patch

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