anitazha / rpms / systemd

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