From 6a5558491b27da3181ac6462add72389b8fd328a Mon Sep 17 00:00:00 2001 From: Shawn Landden Date: Mon, 6 Aug 2018 14:21:39 -0700 Subject: [PATCH] sd-bus: fix test cases on host handling --- src/libsystemd/sd-bus/sd-bus.c | 8 +++++--- src/libsystemd/sd-bus/test-bus-address.c | 20 ++++++++++---------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c index e0a2a08c6ed..0da69a17d6f 100644 --- a/src/libsystemd/sd-bus/sd-bus.c +++ b/src/libsystemd/sd-bus/sd-bus.c @@ -1373,7 +1373,7 @@ int bus_set_address_system_remote(sd_bus *b, const char *host) { e = bus_address_escape(t); if (!e) return -ENOMEM; - } else if ((a = strchr(host, '@'))) + } else if ((a = strchr(host, '@'))) { if (*(a + 1) == '[') { _cleanup_free_ char *t = NULL; @@ -1388,7 +1388,9 @@ int bus_set_address_system_remote(sd_bus *b, const char *host) { e = bus_address_escape(t); if (!e) return -ENOMEM; - } + } else if (*(a + 1) == '\0' || strchr(a + 1, '@')) + return -EINVAL; + } /* Let's see if a port was given */ m = strchr(rbracket ? rbracket + 1 : host, ':'); @@ -1404,7 +1406,7 @@ int bus_set_address_system_remote(sd_bus *b, const char *host) { got_forward_slash = true; } - if (!in_charset(p, "0123456789")) { + if (!in_charset(p, "0123456789") || *p == '\0') { if (!machine_name_is_valid(p) || got_forward_slash) return -EINVAL; else { diff --git a/src/libsystemd/sd-bus/test-bus-address.c b/src/libsystemd/sd-bus/test-bus-address.c index fb3efc3cac7..db5ff72ef44 100644 --- a/src/libsystemd/sd-bus/test-bus-address.c +++ b/src/libsystemd/sd-bus/test-bus-address.c @@ -36,26 +36,26 @@ static void test_bus_set_address_system_remote(char **args) { 0, "unixexec:path=ssh,argv1=-xT,argv2=-p,argv3=123,argv4=--,argv5=host,argv6=systemd-stdio-bridge"); test_one_address(b, "host:123:123", -EINVAL, NULL); - // test_one_address(b, "host:", - // -EINVAL, NULL); + test_one_address(b, "host:", + -EINVAL, NULL); test_one_address(b, "user@host", 0, "unixexec:path=ssh,argv1=-xT,argv2=--,argv3=user%40host,argv4=systemd-stdio-bridge"); - // test_one_address(b, "user@host@host", - // -EINVAL, NULL); + test_one_address(b, "user@host@host", + -EINVAL, NULL); test_one_address(b, "[::1]", 0, "unixexec:path=ssh,argv1=-xT,argv2=--,argv3=%3a%3a1,argv4=systemd-stdio-bridge"); test_one_address(b, "user@[::1]", 0, "unixexec:path=ssh,argv1=-xT,argv2=--,argv3=user%40%3a%3a1,argv4=systemd-stdio-bridge"); test_one_address(b, "user@[::1]:99", 0, "unixexec:path=ssh,argv1=-xT,argv2=-p,argv3=99,argv4=--,argv5=user%40%3a%3a1,argv6=systemd-stdio-bridge"); - //test_one_address(b, "user@[::1]:", - // -EINVAL, NULL); + test_one_address(b, "user@[::1]:", + -EINVAL, NULL); test_one_address(b, "user@[::1:", -EINVAL, NULL); - //test_one_address(b, "user@", - // -EINVAL, NULL); - //test_one_address(b, "user@@", - // -EINVAL, NULL); + test_one_address(b, "user@", + -EINVAL, NULL); + test_one_address(b, "user@@", + -EINVAL, NULL); } int main(int argc, char *argv[]) { -- 2.47.3