]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-bus: fix test cases on host handling 8135/head
authorShawn Landden <shawn@git.icu>
Mon, 6 Aug 2018 21:21:39 +0000 (14:21 -0700)
committerShawn Landden <shawn@git.icu>
Mon, 6 Aug 2018 21:30:53 +0000 (14:30 -0700)
src/libsystemd/sd-bus/sd-bus.c
src/libsystemd/sd-bus/test-bus-address.c

index e0a2a08c6ed9572dbb0e86f3abaa6dc8e291ebab..0da69a17d6f2bed589ef1c1624f1148c350f973e 100644 (file)
@@ -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 {
index fb3efc3cac77934603e43d789adcab1816912060..db5ff72ef4459c47ec575db8fa18a89c7125088e 100644 (file)
@@ -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[]) {