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