sd-bus: fix test cases on host handling

This commit is contained in:
Shawn Landden 2018-08-06 14:21:39 -07:00
parent 8a0c1913e0
commit 6a5558491b
2 changed files with 15 additions and 13 deletions

View 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 {

View 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[]) {