daandemeyer / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
4bff0a
From 94b18b8123b5d957ed84e4aa8e268b60f5427821 Mon Sep 17 00:00:00 2001
563e3e
From: Filipe Brandenburger <filbranden@google.com>
563e3e
Date: Tue, 17 Jul 2018 11:32:40 -0700
563e3e
Subject: [PATCH] bus-socket: Fix line_begins() to accept word matching full
563e3e
 string
563e3e
563e3e
The switch to memory_startswith() changed the logic to only look for a space or
563e3e
NUL byte after the matched word, but matching the full size should also be
563e3e
acceptable.
563e3e
563e3e
This changed the behavior of parsing of "AUTH\r\n", where m will be set to 4,
563e3e
since even though the word will match, the check for it being followed by ' '
563e3e
or NUL will make line_begins() return false.
563e3e
563e3e
Tested:
563e3e
563e3e
- Using netcat to connect to the private socket directly:
563e3e
  $ echo -ne '\0AUTH\r\n' | sudo nc -U /run/systemd/private
563e3e
  REJECTED EXTERNAL ANONYMOUS
563e3e
563e3e
- Running the Ignition blackbox test:
563e3e
  $ sudo sh -c 'PATH=$PWD/bin/amd64:$PATH ./tests.test'
563e3e
  PASS
563e3e
563e3e
Fixes: d27b725abf64a19a6b2f99332b663f17ad046771
563e3e
(cherry picked from commit 3f10c66270b74530339b3f466c43874bb40c210f)
563e3e
563e3e
Resolves: #1692991
563e3e
---
563e3e
 src/libsystemd/sd-bus/bus-socket.c | 5 +----
563e3e
 1 file changed, 1 insertion(+), 4 deletions(-)
563e3e
563e3e
diff --git a/src/libsystemd/sd-bus/bus-socket.c b/src/libsystemd/sd-bus/bus-socket.c
4bff0a
index b147a3843a..a5513d1ab5 100644
563e3e
--- a/src/libsystemd/sd-bus/bus-socket.c
563e3e
+++ b/src/libsystemd/sd-bus/bus-socket.c
563e3e
@@ -248,10 +248,7 @@ static bool line_begins(const char *s, size_t m, const char *word) {
563e3e
         const char *p;
563e3e
 
563e3e
         p = memory_startswith(s, m, word);
563e3e
-        if (!p)
563e3e
-                return false;
563e3e
-
563e3e
-        return IN_SET(*p, 0, ' ');
563e3e
+        return p && (p == (s + m) || *p == ' ');
563e3e
 }
563e3e
 
563e3e
 static int verify_anonymous_token(sd_bus *b, const char *p, size_t l) {