| File: | build-scan/../src/test/test-socket-util.c |
| Warning: | line 562, column 17 Value stored to 'tmpfd' is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
| 2 | |
| 3 | #include <sys/types.h> |
| 4 | #include <unistd.h> |
| 5 | #include <grp.h> |
| 6 | |
| 7 | #include "alloc-util.h" |
| 8 | #include "async.h" |
| 9 | #include "exit-status.h" |
| 10 | #include "fd-util.h" |
| 11 | #include "fileio.h" |
| 12 | #include "in-addr-util.h" |
| 13 | #include "io-util.h" |
| 14 | #include "log.h" |
| 15 | #include "macro.h" |
| 16 | #include "process-util.h" |
| 17 | #include "socket-util.h" |
| 18 | #include "string-util.h" |
| 19 | #include "util.h" |
| 20 | |
| 21 | static void test_ifname_valid(void) { |
| 22 | assert(ifname_valid("foo"))do { if ((__builtin_expect(!!(!(ifname_valid("foo"))),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("ifname_valid(\"foo\")"), "../src/test/test-socket-util.c" , 22, __PRETTY_FUNCTION__); } while (0); |
| 23 | assert(ifname_valid("eth0"))do { if ((__builtin_expect(!!(!(ifname_valid("eth0"))),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("ifname_valid(\"eth0\")"), "../src/test/test-socket-util.c" , 23, __PRETTY_FUNCTION__); } while (0); |
| 24 | |
| 25 | assert(!ifname_valid("0"))do { if ((__builtin_expect(!!(!(!ifname_valid("0"))),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("!ifname_valid(\"0\")"), "../src/test/test-socket-util.c" , 25, __PRETTY_FUNCTION__); } while (0); |
| 26 | assert(!ifname_valid("99"))do { if ((__builtin_expect(!!(!(!ifname_valid("99"))),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("!ifname_valid(\"99\")"), "../src/test/test-socket-util.c" , 26, __PRETTY_FUNCTION__); } while (0); |
| 27 | assert(ifname_valid("a99"))do { if ((__builtin_expect(!!(!(ifname_valid("a99"))),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("ifname_valid(\"a99\")"), "../src/test/test-socket-util.c" , 27, __PRETTY_FUNCTION__); } while (0); |
| 28 | assert(ifname_valid("99a"))do { if ((__builtin_expect(!!(!(ifname_valid("99a"))),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("ifname_valid(\"99a\")"), "../src/test/test-socket-util.c" , 28, __PRETTY_FUNCTION__); } while (0); |
| 29 | |
| 30 | assert(!ifname_valid(NULL))do { if ((__builtin_expect(!!(!(!ifname_valid(((void*)0)))),0 ))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!ifname_valid(NULL)" ), "../src/test/test-socket-util.c", 30, __PRETTY_FUNCTION__) ; } while (0); |
| 31 | assert(!ifname_valid(""))do { if ((__builtin_expect(!!(!(!ifname_valid(""))),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("!ifname_valid(\"\")"), "../src/test/test-socket-util.c" , 31, __PRETTY_FUNCTION__); } while (0); |
| 32 | assert(!ifname_valid(" "))do { if ((__builtin_expect(!!(!(!ifname_valid(" "))),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("!ifname_valid(\" \")"), "../src/test/test-socket-util.c" , 32, __PRETTY_FUNCTION__); } while (0); |
| 33 | assert(!ifname_valid(" foo"))do { if ((__builtin_expect(!!(!(!ifname_valid(" foo"))),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("!ifname_valid(\" foo\")"), "../src/test/test-socket-util.c" , 33, __PRETTY_FUNCTION__); } while (0); |
| 34 | assert(!ifname_valid("bar\n"))do { if ((__builtin_expect(!!(!(!ifname_valid("bar\n"))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!ifname_valid(\"bar\\n\")" ), "../src/test/test-socket-util.c", 34, __PRETTY_FUNCTION__) ; } while (0); |
| 35 | assert(!ifname_valid("."))do { if ((__builtin_expect(!!(!(!ifname_valid("."))),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("!ifname_valid(\".\")"), "../src/test/test-socket-util.c" , 35, __PRETTY_FUNCTION__); } while (0); |
| 36 | assert(!ifname_valid(".."))do { if ((__builtin_expect(!!(!(!ifname_valid(".."))),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("!ifname_valid(\"..\")"), "../src/test/test-socket-util.c" , 36, __PRETTY_FUNCTION__); } while (0); |
| 37 | assert(ifname_valid("foo.bar"))do { if ((__builtin_expect(!!(!(ifname_valid("foo.bar"))),0)) ) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("ifname_valid(\"foo.bar\")" ), "../src/test/test-socket-util.c", 37, __PRETTY_FUNCTION__) ; } while (0); |
| 38 | assert(!ifname_valid("x:y"))do { if ((__builtin_expect(!!(!(!ifname_valid("x:y"))),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("!ifname_valid(\"x:y\")"), "../src/test/test-socket-util.c" , 38, __PRETTY_FUNCTION__); } while (0); |
| 39 | |
| 40 | assert(ifname_valid("xxxxxxxxxxxxxxx"))do { if ((__builtin_expect(!!(!(ifname_valid("xxxxxxxxxxxxxxx" ))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("ifname_valid(\"xxxxxxxxxxxxxxx\")" ), "../src/test/test-socket-util.c", 40, __PRETTY_FUNCTION__) ; } while (0); |
| 41 | assert(!ifname_valid("xxxxxxxxxxxxxxxx"))do { if ((__builtin_expect(!!(!(!ifname_valid("xxxxxxxxxxxxxxxx" ))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!ifname_valid(\"xxxxxxxxxxxxxxxx\")" ), "../src/test/test-socket-util.c", 41, __PRETTY_FUNCTION__) ; } while (0); |
| 42 | } |
| 43 | |
| 44 | static void test_socket_address_parse(void) { |
| 45 | SocketAddress a; |
| 46 | |
| 47 | assert_se(socket_address_parse(&a, "junk") < 0)do { if ((__builtin_expect(!!(!(socket_address_parse(&a, "junk" ) < 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("socket_address_parse(&a, \"junk\") < 0" ), "../src/test/test-socket-util.c", 47, __PRETTY_FUNCTION__) ; } while (0); |
| 48 | assert_se(socket_address_parse(&a, "192.168.1.1") < 0)do { if ((__builtin_expect(!!(!(socket_address_parse(&a, "192.168.1.1" ) < 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("socket_address_parse(&a, \"192.168.1.1\") < 0" ), "../src/test/test-socket-util.c", 48, __PRETTY_FUNCTION__) ; } while (0); |
| 49 | assert_se(socket_address_parse(&a, ".168.1.1") < 0)do { if ((__builtin_expect(!!(!(socket_address_parse(&a, ".168.1.1" ) < 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("socket_address_parse(&a, \".168.1.1\") < 0" ), "../src/test/test-socket-util.c", 49, __PRETTY_FUNCTION__) ; } while (0); |
| 50 | assert_se(socket_address_parse(&a, "989.168.1.1") < 0)do { if ((__builtin_expect(!!(!(socket_address_parse(&a, "989.168.1.1" ) < 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("socket_address_parse(&a, \"989.168.1.1\") < 0" ), "../src/test/test-socket-util.c", 50, __PRETTY_FUNCTION__) ; } while (0); |
| 51 | assert_se(socket_address_parse(&a, "192.168.1.1:65536") < 0)do { if ((__builtin_expect(!!(!(socket_address_parse(&a, "192.168.1.1:65536" ) < 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("socket_address_parse(&a, \"192.168.1.1:65536\") < 0" ), "../src/test/test-socket-util.c", 51, __PRETTY_FUNCTION__) ; } while (0); |
| 52 | assert_se(socket_address_parse(&a, "192.168.1.1:0") < 0)do { if ((__builtin_expect(!!(!(socket_address_parse(&a, "192.168.1.1:0" ) < 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("socket_address_parse(&a, \"192.168.1.1:0\") < 0" ), "../src/test/test-socket-util.c", 52, __PRETTY_FUNCTION__) ; } while (0); |
| 53 | assert_se(socket_address_parse(&a, "0") < 0)do { if ((__builtin_expect(!!(!(socket_address_parse(&a, "0" ) < 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("socket_address_parse(&a, \"0\") < 0" ), "../src/test/test-socket-util.c", 53, __PRETTY_FUNCTION__) ; } while (0); |
| 54 | assert_se(socket_address_parse(&a, "65536") < 0)do { if ((__builtin_expect(!!(!(socket_address_parse(&a, "65536" ) < 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("socket_address_parse(&a, \"65536\") < 0" ), "../src/test/test-socket-util.c", 54, __PRETTY_FUNCTION__) ; } while (0); |
| 55 | |
| 56 | assert_se(socket_address_parse(&a, "65535") >= 0)do { if ((__builtin_expect(!!(!(socket_address_parse(&a, "65535" ) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ( "socket_address_parse(&a, \"65535\") >= 0"), "../src/test/test-socket-util.c" , 56, __PRETTY_FUNCTION__); } while (0); |
| 57 | |
| 58 | /* The checks below will pass even if ipv6 is disabled in |
| 59 | * kernel. The underlying glibc's inet_pton() is just a string |
| 60 | * parser and doesn't make any syscalls. */ |
| 61 | |
| 62 | assert_se(socket_address_parse(&a, "[::1]") < 0)do { if ((__builtin_expect(!!(!(socket_address_parse(&a, "[::1]" ) < 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("socket_address_parse(&a, \"[::1]\") < 0" ), "../src/test/test-socket-util.c", 62, __PRETTY_FUNCTION__) ; } while (0); |
| 63 | assert_se(socket_address_parse(&a, "[::1]8888") < 0)do { if ((__builtin_expect(!!(!(socket_address_parse(&a, "[::1]8888" ) < 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("socket_address_parse(&a, \"[::1]8888\") < 0" ), "../src/test/test-socket-util.c", 63, __PRETTY_FUNCTION__) ; } while (0); |
| 64 | assert_se(socket_address_parse(&a, "::1") < 0)do { if ((__builtin_expect(!!(!(socket_address_parse(&a, "::1" ) < 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("socket_address_parse(&a, \"::1\") < 0" ), "../src/test/test-socket-util.c", 64, __PRETTY_FUNCTION__) ; } while (0); |
| 65 | assert_se(socket_address_parse(&a, "[::1]:0") < 0)do { if ((__builtin_expect(!!(!(socket_address_parse(&a, "[::1]:0" ) < 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("socket_address_parse(&a, \"[::1]:0\") < 0" ), "../src/test/test-socket-util.c", 65, __PRETTY_FUNCTION__) ; } while (0); |
| 66 | assert_se(socket_address_parse(&a, "[::1]:65536") < 0)do { if ((__builtin_expect(!!(!(socket_address_parse(&a, "[::1]:65536" ) < 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("socket_address_parse(&a, \"[::1]:65536\") < 0" ), "../src/test/test-socket-util.c", 66, __PRETTY_FUNCTION__) ; } while (0); |
| 67 | assert_se(socket_address_parse(&a, "[a:b:1]:8888") < 0)do { if ((__builtin_expect(!!(!(socket_address_parse(&a, "[a:b:1]:8888" ) < 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("socket_address_parse(&a, \"[a:b:1]:8888\") < 0" ), "../src/test/test-socket-util.c", 67, __PRETTY_FUNCTION__) ; } while (0); |
| 68 | |
| 69 | assert_se(socket_address_parse(&a, "8888") >= 0)do { if ((__builtin_expect(!!(!(socket_address_parse(&a, "8888" ) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ( "socket_address_parse(&a, \"8888\") >= 0"), "../src/test/test-socket-util.c" , 69, __PRETTY_FUNCTION__); } while (0); |
| 70 | assert_se(a.sockaddr.sa.sa_family == (socket_ipv6_is_supported() ? AF_INET6 : AF_INET))do { if ((__builtin_expect(!!(!(a.sockaddr.sa.sa_family == (socket_ipv6_is_supported () ? 10 : 2))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("a.sockaddr.sa.sa_family == (socket_ipv6_is_supported() ? AF_INET6 : AF_INET)" ), "../src/test/test-socket-util.c", 70, __PRETTY_FUNCTION__) ; } while (0); |
| 71 | |
| 72 | assert_se(socket_address_parse(&a, "[2001:0db8:0000:85a3:0000:0000:ac1f:8001]:8888") >= 0)do { if ((__builtin_expect(!!(!(socket_address_parse(&a, "[2001:0db8:0000:85a3:0000:0000:ac1f:8001]:8888" ) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ( "socket_address_parse(&a, \"[2001:0db8:0000:85a3:0000:0000:ac1f:8001]:8888\") >= 0" ), "../src/test/test-socket-util.c", 72, __PRETTY_FUNCTION__) ; } while (0); |
| 73 | assert_se(a.sockaddr.sa.sa_family == AF_INET6)do { if ((__builtin_expect(!!(!(a.sockaddr.sa.sa_family == 10 )),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("a.sockaddr.sa.sa_family == AF_INET6" ), "../src/test/test-socket-util.c", 73, __PRETTY_FUNCTION__) ; } while (0); |
| 74 | |
| 75 | assert_se(socket_address_parse(&a, "[::1]:8888") >= 0)do { if ((__builtin_expect(!!(!(socket_address_parse(&a, "[::1]:8888" ) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ( "socket_address_parse(&a, \"[::1]:8888\") >= 0"), "../src/test/test-socket-util.c" , 75, __PRETTY_FUNCTION__); } while (0); |
| 76 | assert_se(a.sockaddr.sa.sa_family == AF_INET6)do { if ((__builtin_expect(!!(!(a.sockaddr.sa.sa_family == 10 )),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("a.sockaddr.sa.sa_family == AF_INET6" ), "../src/test/test-socket-util.c", 76, __PRETTY_FUNCTION__) ; } while (0); |
| 77 | |
| 78 | assert_se(socket_address_parse(&a, "192.168.1.254:8888") >= 0)do { if ((__builtin_expect(!!(!(socket_address_parse(&a, "192.168.1.254:8888" ) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ( "socket_address_parse(&a, \"192.168.1.254:8888\") >= 0" ), "../src/test/test-socket-util.c", 78, __PRETTY_FUNCTION__) ; } while (0); |
| 79 | assert_se(a.sockaddr.sa.sa_family == AF_INET)do { if ((__builtin_expect(!!(!(a.sockaddr.sa.sa_family == 2) ),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("a.sockaddr.sa.sa_family == AF_INET" ), "../src/test/test-socket-util.c", 79, __PRETTY_FUNCTION__) ; } while (0); |
| 80 | |
| 81 | assert_se(socket_address_parse(&a, "/foo/bar") >= 0)do { if ((__builtin_expect(!!(!(socket_address_parse(&a, "/foo/bar" ) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ( "socket_address_parse(&a, \"/foo/bar\") >= 0"), "../src/test/test-socket-util.c" , 81, __PRETTY_FUNCTION__); } while (0); |
| 82 | assert_se(a.sockaddr.sa.sa_family == AF_UNIX)do { if ((__builtin_expect(!!(!(a.sockaddr.sa.sa_family == 1) ),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("a.sockaddr.sa.sa_family == AF_UNIX" ), "../src/test/test-socket-util.c", 82, __PRETTY_FUNCTION__) ; } while (0); |
| 83 | |
| 84 | assert_se(socket_address_parse(&a, "@abstract") >= 0)do { if ((__builtin_expect(!!(!(socket_address_parse(&a, "@abstract" ) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ( "socket_address_parse(&a, \"@abstract\") >= 0"), "../src/test/test-socket-util.c" , 84, __PRETTY_FUNCTION__); } while (0); |
| 85 | assert_se(a.sockaddr.sa.sa_family == AF_UNIX)do { if ((__builtin_expect(!!(!(a.sockaddr.sa.sa_family == 1) ),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("a.sockaddr.sa.sa_family == AF_UNIX" ), "../src/test/test-socket-util.c", 85, __PRETTY_FUNCTION__) ; } while (0); |
| 86 | |
| 87 | assert_se(socket_address_parse(&a, "vsock::1234") >= 0)do { if ((__builtin_expect(!!(!(socket_address_parse(&a, "vsock::1234" ) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ( "socket_address_parse(&a, \"vsock::1234\") >= 0"), "../src/test/test-socket-util.c" , 87, __PRETTY_FUNCTION__); } while (0); |
| 88 | assert_se(a.sockaddr.sa.sa_family == AF_VSOCK)do { if ((__builtin_expect(!!(!(a.sockaddr.sa.sa_family == 40 )),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("a.sockaddr.sa.sa_family == AF_VSOCK" ), "../src/test/test-socket-util.c", 88, __PRETTY_FUNCTION__) ; } while (0); |
| 89 | assert_se(socket_address_parse(&a, "vsock:2:1234") >= 0)do { if ((__builtin_expect(!!(!(socket_address_parse(&a, "vsock:2:1234" ) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ( "socket_address_parse(&a, \"vsock:2:1234\") >= 0"), "../src/test/test-socket-util.c" , 89, __PRETTY_FUNCTION__); } while (0); |
| 90 | assert_se(a.sockaddr.sa.sa_family == AF_VSOCK)do { if ((__builtin_expect(!!(!(a.sockaddr.sa.sa_family == 40 )),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("a.sockaddr.sa.sa_family == AF_VSOCK" ), "../src/test/test-socket-util.c", 90, __PRETTY_FUNCTION__) ; } while (0); |
| 91 | assert_se(socket_address_parse(&a, "vsock:2:1234x") < 0)do { if ((__builtin_expect(!!(!(socket_address_parse(&a, "vsock:2:1234x" ) < 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("socket_address_parse(&a, \"vsock:2:1234x\") < 0" ), "../src/test/test-socket-util.c", 91, __PRETTY_FUNCTION__) ; } while (0); |
| 92 | assert_se(socket_address_parse(&a, "vsock:2x:1234") < 0)do { if ((__builtin_expect(!!(!(socket_address_parse(&a, "vsock:2x:1234" ) < 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("socket_address_parse(&a, \"vsock:2x:1234\") < 0" ), "../src/test/test-socket-util.c", 92, __PRETTY_FUNCTION__) ; } while (0); |
| 93 | assert_se(socket_address_parse(&a, "vsock:2") < 0)do { if ((__builtin_expect(!!(!(socket_address_parse(&a, "vsock:2" ) < 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("socket_address_parse(&a, \"vsock:2\") < 0" ), "../src/test/test-socket-util.c", 93, __PRETTY_FUNCTION__) ; } while (0); |
| 94 | } |
| 95 | |
| 96 | static void test_socket_address_parse_netlink(void) { |
| 97 | SocketAddress a; |
| 98 | |
| 99 | assert_se(socket_address_parse_netlink(&a, "junk") < 0)do { if ((__builtin_expect(!!(!(socket_address_parse_netlink( &a, "junk") < 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("socket_address_parse_netlink(&a, \"junk\") < 0"), "../src/test/test-socket-util.c" , 99, __PRETTY_FUNCTION__); } while (0); |
| 100 | assert_se(socket_address_parse_netlink(&a, "") < 0)do { if ((__builtin_expect(!!(!(socket_address_parse_netlink( &a, "") < 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("socket_address_parse_netlink(&a, \"\") < 0"), "../src/test/test-socket-util.c" , 100, __PRETTY_FUNCTION__); } while (0); |
| 101 | |
| 102 | assert_se(socket_address_parse_netlink(&a, "route") >= 0)do { if ((__builtin_expect(!!(!(socket_address_parse_netlink( &a, "route") >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("socket_address_parse_netlink(&a, \"route\") >= 0") , "../src/test/test-socket-util.c", 102, __PRETTY_FUNCTION__) ; } while (0); |
| 103 | assert_se(socket_address_parse_netlink(&a, "route 10") >= 0)do { if ((__builtin_expect(!!(!(socket_address_parse_netlink( &a, "route 10") >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("socket_address_parse_netlink(&a, \"route 10\") >= 0" ), "../src/test/test-socket-util.c", 103, __PRETTY_FUNCTION__ ); } while (0); |
| 104 | assert_se(a.sockaddr.sa.sa_family == AF_NETLINK)do { if ((__builtin_expect(!!(!(a.sockaddr.sa.sa_family == 16 )),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("a.sockaddr.sa.sa_family == AF_NETLINK" ), "../src/test/test-socket-util.c", 104, __PRETTY_FUNCTION__ ); } while (0); |
| 105 | assert_se(a.protocol == NETLINK_ROUTE)do { if ((__builtin_expect(!!(!(a.protocol == 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("a.protocol == NETLINK_ROUTE"), "../src/test/test-socket-util.c" , 105, __PRETTY_FUNCTION__); } while (0); |
| 106 | |
| 107 | /* With spaces and tabs */ |
| 108 | assert_se(socket_address_parse_netlink(&a, " kobject-uevent ") >= 0)do { if ((__builtin_expect(!!(!(socket_address_parse_netlink( &a, " kobject-uevent ") >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("socket_address_parse_netlink(&a, \" kobject-uevent \") >= 0" ), "../src/test/test-socket-util.c", 108, __PRETTY_FUNCTION__ ); } while (0); |
| 109 | assert_se(socket_address_parse_netlink(&a, " \t kobject-uevent \t 10 \t") >= 0)do { if ((__builtin_expect(!!(!(socket_address_parse_netlink( &a, " \t kobject-uevent \t 10 \t") >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("socket_address_parse_netlink(&a, \" \\t kobject-uevent \\t 10 \\t\") >= 0" ), "../src/test/test-socket-util.c", 109, __PRETTY_FUNCTION__ ); } while (0); |
| 110 | assert_se(a.sockaddr.sa.sa_family == AF_NETLINK)do { if ((__builtin_expect(!!(!(a.sockaddr.sa.sa_family == 16 )),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("a.sockaddr.sa.sa_family == AF_NETLINK" ), "../src/test/test-socket-util.c", 110, __PRETTY_FUNCTION__ ); } while (0); |
| 111 | assert_se(a.protocol == NETLINK_KOBJECT_UEVENT)do { if ((__builtin_expect(!!(!(a.protocol == 15)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("a.protocol == NETLINK_KOBJECT_UEVENT"), "../src/test/test-socket-util.c", 111, __PRETTY_FUNCTION__); } while (0); |
| 112 | |
| 113 | assert_se(socket_address_parse_netlink(&a, "kobject-uevent\t10") >= 0)do { if ((__builtin_expect(!!(!(socket_address_parse_netlink( &a, "kobject-uevent\t10") >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("socket_address_parse_netlink(&a, \"kobject-uevent\\t10\") >= 0" ), "../src/test/test-socket-util.c", 113, __PRETTY_FUNCTION__ ); } while (0); |
| 114 | assert_se(a.sockaddr.sa.sa_family == AF_NETLINK)do { if ((__builtin_expect(!!(!(a.sockaddr.sa.sa_family == 16 )),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("a.sockaddr.sa.sa_family == AF_NETLINK" ), "../src/test/test-socket-util.c", 114, __PRETTY_FUNCTION__ ); } while (0); |
| 115 | assert_se(a.protocol == NETLINK_KOBJECT_UEVENT)do { if ((__builtin_expect(!!(!(a.protocol == 15)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("a.protocol == NETLINK_KOBJECT_UEVENT"), "../src/test/test-socket-util.c", 115, __PRETTY_FUNCTION__); } while (0); |
| 116 | |
| 117 | /* oss-fuzz #6884 */ |
| 118 | assert_se(socket_address_parse_netlink(&a, "\xff") < 0)do { if ((__builtin_expect(!!(!(socket_address_parse_netlink( &a, "\xff") < 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("socket_address_parse_netlink(&a, \"\\xff\") < 0"), "../src/test/test-socket-util.c", 118, __PRETTY_FUNCTION__); } while (0); |
| 119 | } |
| 120 | |
| 121 | static void test_socket_address_equal(void) { |
| 122 | SocketAddress a; |
| 123 | SocketAddress b; |
| 124 | |
| 125 | assert_se(socket_address_parse(&a, "192.168.1.1:8888") >= 0)do { if ((__builtin_expect(!!(!(socket_address_parse(&a, "192.168.1.1:8888" ) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ( "socket_address_parse(&a, \"192.168.1.1:8888\") >= 0") , "../src/test/test-socket-util.c", 125, __PRETTY_FUNCTION__) ; } while (0); |
| 126 | assert_se(socket_address_parse(&b, "192.168.1.1:888") >= 0)do { if ((__builtin_expect(!!(!(socket_address_parse(&b, "192.168.1.1:888" ) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ( "socket_address_parse(&b, \"192.168.1.1:888\") >= 0"), "../src/test/test-socket-util.c", 126, __PRETTY_FUNCTION__); } while (0); |
| 127 | assert_se(!socket_address_equal(&a, &b))do { if ((__builtin_expect(!!(!(!socket_address_equal(&a, &b))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!socket_address_equal(&a, &b)" ), "../src/test/test-socket-util.c", 127, __PRETTY_FUNCTION__ ); } while (0); |
| 128 | |
| 129 | assert_se(socket_address_parse(&a, "192.168.1.1:8888") >= 0)do { if ((__builtin_expect(!!(!(socket_address_parse(&a, "192.168.1.1:8888" ) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ( "socket_address_parse(&a, \"192.168.1.1:8888\") >= 0") , "../src/test/test-socket-util.c", 129, __PRETTY_FUNCTION__) ; } while (0); |
| 130 | assert_se(socket_address_parse(&b, "192.16.1.1:8888") >= 0)do { if ((__builtin_expect(!!(!(socket_address_parse(&b, "192.16.1.1:8888" ) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ( "socket_address_parse(&b, \"192.16.1.1:8888\") >= 0"), "../src/test/test-socket-util.c", 130, __PRETTY_FUNCTION__); } while (0); |
| 131 | assert_se(!socket_address_equal(&a, &b))do { if ((__builtin_expect(!!(!(!socket_address_equal(&a, &b))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!socket_address_equal(&a, &b)" ), "../src/test/test-socket-util.c", 131, __PRETTY_FUNCTION__ ); } while (0); |
| 132 | |
| 133 | assert_se(socket_address_parse(&a, "192.168.1.1:8888") >= 0)do { if ((__builtin_expect(!!(!(socket_address_parse(&a, "192.168.1.1:8888" ) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ( "socket_address_parse(&a, \"192.168.1.1:8888\") >= 0") , "../src/test/test-socket-util.c", 133, __PRETTY_FUNCTION__) ; } while (0); |
| 134 | assert_se(socket_address_parse(&b, "8888") >= 0)do { if ((__builtin_expect(!!(!(socket_address_parse(&b, "8888" ) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ( "socket_address_parse(&b, \"8888\") >= 0"), "../src/test/test-socket-util.c" , 134, __PRETTY_FUNCTION__); } while (0); |
| 135 | assert_se(!socket_address_equal(&a, &b))do { if ((__builtin_expect(!!(!(!socket_address_equal(&a, &b))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!socket_address_equal(&a, &b)" ), "../src/test/test-socket-util.c", 135, __PRETTY_FUNCTION__ ); } while (0); |
| 136 | |
| 137 | assert_se(socket_address_parse(&a, "192.168.1.1:8888") >= 0)do { if ((__builtin_expect(!!(!(socket_address_parse(&a, "192.168.1.1:8888" ) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ( "socket_address_parse(&a, \"192.168.1.1:8888\") >= 0") , "../src/test/test-socket-util.c", 137, __PRETTY_FUNCTION__) ; } while (0); |
| 138 | assert_se(socket_address_parse(&b, "/foo/bar/") >= 0)do { if ((__builtin_expect(!!(!(socket_address_parse(&b, "/foo/bar/" ) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ( "socket_address_parse(&b, \"/foo/bar/\") >= 0"), "../src/test/test-socket-util.c" , 138, __PRETTY_FUNCTION__); } while (0); |
| 139 | assert_se(!socket_address_equal(&a, &b))do { if ((__builtin_expect(!!(!(!socket_address_equal(&a, &b))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!socket_address_equal(&a, &b)" ), "../src/test/test-socket-util.c", 139, __PRETTY_FUNCTION__ ); } while (0); |
| 140 | |
| 141 | assert_se(socket_address_parse(&a, "192.168.1.1:8888") >= 0)do { if ((__builtin_expect(!!(!(socket_address_parse(&a, "192.168.1.1:8888" ) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ( "socket_address_parse(&a, \"192.168.1.1:8888\") >= 0") , "../src/test/test-socket-util.c", 141, __PRETTY_FUNCTION__) ; } while (0); |
| 142 | assert_se(socket_address_parse(&b, "192.168.1.1:8888") >= 0)do { if ((__builtin_expect(!!(!(socket_address_parse(&b, "192.168.1.1:8888" ) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ( "socket_address_parse(&b, \"192.168.1.1:8888\") >= 0") , "../src/test/test-socket-util.c", 142, __PRETTY_FUNCTION__) ; } while (0); |
| 143 | assert_se(socket_address_equal(&a, &b))do { if ((__builtin_expect(!!(!(socket_address_equal(&a, & b))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("socket_address_equal(&a, &b)" ), "../src/test/test-socket-util.c", 143, __PRETTY_FUNCTION__ ); } while (0); |
| 144 | |
| 145 | assert_se(socket_address_parse(&a, "/foo/bar") >= 0)do { if ((__builtin_expect(!!(!(socket_address_parse(&a, "/foo/bar" ) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ( "socket_address_parse(&a, \"/foo/bar\") >= 0"), "../src/test/test-socket-util.c" , 145, __PRETTY_FUNCTION__); } while (0); |
| 146 | assert_se(socket_address_parse(&b, "/foo/bar") >= 0)do { if ((__builtin_expect(!!(!(socket_address_parse(&b, "/foo/bar" ) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ( "socket_address_parse(&b, \"/foo/bar\") >= 0"), "../src/test/test-socket-util.c" , 146, __PRETTY_FUNCTION__); } while (0); |
| 147 | assert_se(socket_address_equal(&a, &b))do { if ((__builtin_expect(!!(!(socket_address_equal(&a, & b))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("socket_address_equal(&a, &b)" ), "../src/test/test-socket-util.c", 147, __PRETTY_FUNCTION__ ); } while (0); |
| 148 | |
| 149 | assert_se(socket_address_parse(&a, "[::1]:8888") >= 0)do { if ((__builtin_expect(!!(!(socket_address_parse(&a, "[::1]:8888" ) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ( "socket_address_parse(&a, \"[::1]:8888\") >= 0"), "../src/test/test-socket-util.c" , 149, __PRETTY_FUNCTION__); } while (0); |
| 150 | assert_se(socket_address_parse(&b, "[::1]:8888") >= 0)do { if ((__builtin_expect(!!(!(socket_address_parse(&b, "[::1]:8888" ) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ( "socket_address_parse(&b, \"[::1]:8888\") >= 0"), "../src/test/test-socket-util.c" , 150, __PRETTY_FUNCTION__); } while (0); |
| 151 | assert_se(socket_address_equal(&a, &b))do { if ((__builtin_expect(!!(!(socket_address_equal(&a, & b))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("socket_address_equal(&a, &b)" ), "../src/test/test-socket-util.c", 151, __PRETTY_FUNCTION__ ); } while (0); |
| 152 | |
| 153 | assert_se(socket_address_parse(&a, "@abstract") >= 0)do { if ((__builtin_expect(!!(!(socket_address_parse(&a, "@abstract" ) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ( "socket_address_parse(&a, \"@abstract\") >= 0"), "../src/test/test-socket-util.c" , 153, __PRETTY_FUNCTION__); } while (0); |
| 154 | assert_se(socket_address_parse(&b, "@abstract") >= 0)do { if ((__builtin_expect(!!(!(socket_address_parse(&b, "@abstract" ) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ( "socket_address_parse(&b, \"@abstract\") >= 0"), "../src/test/test-socket-util.c" , 154, __PRETTY_FUNCTION__); } while (0); |
| 155 | assert_se(socket_address_equal(&a, &b))do { if ((__builtin_expect(!!(!(socket_address_equal(&a, & b))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("socket_address_equal(&a, &b)" ), "../src/test/test-socket-util.c", 155, __PRETTY_FUNCTION__ ); } while (0); |
| 156 | |
| 157 | assert_se(socket_address_parse_netlink(&a, "firewall") >= 0)do { if ((__builtin_expect(!!(!(socket_address_parse_netlink( &a, "firewall") >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("socket_address_parse_netlink(&a, \"firewall\") >= 0" ), "../src/test/test-socket-util.c", 157, __PRETTY_FUNCTION__ ); } while (0); |
| 158 | assert_se(socket_address_parse_netlink(&b, "firewall") >= 0)do { if ((__builtin_expect(!!(!(socket_address_parse_netlink( &b, "firewall") >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("socket_address_parse_netlink(&b, \"firewall\") >= 0" ), "../src/test/test-socket-util.c", 158, __PRETTY_FUNCTION__ ); } while (0); |
| 159 | assert_se(socket_address_equal(&a, &b))do { if ((__builtin_expect(!!(!(socket_address_equal(&a, & b))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("socket_address_equal(&a, &b)" ), "../src/test/test-socket-util.c", 159, __PRETTY_FUNCTION__ ); } while (0); |
| 160 | |
| 161 | assert_se(socket_address_parse(&a, "vsock:2:1234") >= 0)do { if ((__builtin_expect(!!(!(socket_address_parse(&a, "vsock:2:1234" ) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ( "socket_address_parse(&a, \"vsock:2:1234\") >= 0"), "../src/test/test-socket-util.c" , 161, __PRETTY_FUNCTION__); } while (0); |
| 162 | assert_se(socket_address_parse(&b, "vsock:2:1234") >= 0)do { if ((__builtin_expect(!!(!(socket_address_parse(&b, "vsock:2:1234" ) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ( "socket_address_parse(&b, \"vsock:2:1234\") >= 0"), "../src/test/test-socket-util.c" , 162, __PRETTY_FUNCTION__); } while (0); |
| 163 | assert_se(socket_address_equal(&a, &b))do { if ((__builtin_expect(!!(!(socket_address_equal(&a, & b))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("socket_address_equal(&a, &b)" ), "../src/test/test-socket-util.c", 163, __PRETTY_FUNCTION__ ); } while (0); |
| 164 | assert_se(socket_address_parse(&b, "vsock:2:1235") >= 0)do { if ((__builtin_expect(!!(!(socket_address_parse(&b, "vsock:2:1235" ) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ( "socket_address_parse(&b, \"vsock:2:1235\") >= 0"), "../src/test/test-socket-util.c" , 164, __PRETTY_FUNCTION__); } while (0); |
| 165 | assert_se(!socket_address_equal(&a, &b))do { if ((__builtin_expect(!!(!(!socket_address_equal(&a, &b))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!socket_address_equal(&a, &b)" ), "../src/test/test-socket-util.c", 165, __PRETTY_FUNCTION__ ); } while (0); |
| 166 | assert_se(socket_address_parse(&b, "vsock:3:1234") >= 0)do { if ((__builtin_expect(!!(!(socket_address_parse(&b, "vsock:3:1234" ) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ( "socket_address_parse(&b, \"vsock:3:1234\") >= 0"), "../src/test/test-socket-util.c" , 166, __PRETTY_FUNCTION__); } while (0); |
| 167 | assert_se(!socket_address_equal(&a, &b))do { if ((__builtin_expect(!!(!(!socket_address_equal(&a, &b))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!socket_address_equal(&a, &b)" ), "../src/test/test-socket-util.c", 167, __PRETTY_FUNCTION__ ); } while (0); |
| 168 | } |
| 169 | |
| 170 | static void test_socket_address_get_path(void) { |
| 171 | SocketAddress a; |
| 172 | |
| 173 | assert_se(socket_address_parse(&a, "192.168.1.1:8888") >= 0)do { if ((__builtin_expect(!!(!(socket_address_parse(&a, "192.168.1.1:8888" ) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ( "socket_address_parse(&a, \"192.168.1.1:8888\") >= 0") , "../src/test/test-socket-util.c", 173, __PRETTY_FUNCTION__) ; } while (0); |
| 174 | assert_se(!socket_address_get_path(&a))do { if ((__builtin_expect(!!(!(!socket_address_get_path(& a))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!socket_address_get_path(&a)" ), "../src/test/test-socket-util.c", 174, __PRETTY_FUNCTION__ ); } while (0); |
| 175 | |
| 176 | assert_se(socket_address_parse(&a, "@abstract") >= 0)do { if ((__builtin_expect(!!(!(socket_address_parse(&a, "@abstract" ) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ( "socket_address_parse(&a, \"@abstract\") >= 0"), "../src/test/test-socket-util.c" , 176, __PRETTY_FUNCTION__); } while (0); |
| 177 | assert_se(!socket_address_get_path(&a))do { if ((__builtin_expect(!!(!(!socket_address_get_path(& a))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!socket_address_get_path(&a)" ), "../src/test/test-socket-util.c", 177, __PRETTY_FUNCTION__ ); } while (0); |
| 178 | |
| 179 | assert_se(socket_address_parse(&a, "[::1]:8888") >= 0)do { if ((__builtin_expect(!!(!(socket_address_parse(&a, "[::1]:8888" ) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ( "socket_address_parse(&a, \"[::1]:8888\") >= 0"), "../src/test/test-socket-util.c" , 179, __PRETTY_FUNCTION__); } while (0); |
| 180 | assert_se(!socket_address_get_path(&a))do { if ((__builtin_expect(!!(!(!socket_address_get_path(& a))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!socket_address_get_path(&a)" ), "../src/test/test-socket-util.c", 180, __PRETTY_FUNCTION__ ); } while (0); |
| 181 | |
| 182 | assert_se(socket_address_parse(&a, "/foo/bar") >= 0)do { if ((__builtin_expect(!!(!(socket_address_parse(&a, "/foo/bar" ) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ( "socket_address_parse(&a, \"/foo/bar\") >= 0"), "../src/test/test-socket-util.c" , 182, __PRETTY_FUNCTION__); } while (0); |
| 183 | assert_se(streq(socket_address_get_path(&a), "/foo/bar"))do { if ((__builtin_expect(!!(!((strcmp((socket_address_get_path (&a)),("/foo/bar")) == 0))),0))) log_assert_failed_realm( LOG_REALM_SYSTEMD, ("streq(socket_address_get_path(&a), \"/foo/bar\")" ), "../src/test/test-socket-util.c", 183, __PRETTY_FUNCTION__ ); } while (0); |
| 184 | |
| 185 | assert_se(socket_address_parse(&a, "vsock:2:1234") >= 0)do { if ((__builtin_expect(!!(!(socket_address_parse(&a, "vsock:2:1234" ) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ( "socket_address_parse(&a, \"vsock:2:1234\") >= 0"), "../src/test/test-socket-util.c" , 185, __PRETTY_FUNCTION__); } while (0); |
| 186 | assert_se(!socket_address_get_path(&a))do { if ((__builtin_expect(!!(!(!socket_address_get_path(& a))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!socket_address_get_path(&a)" ), "../src/test/test-socket-util.c", 186, __PRETTY_FUNCTION__ ); } while (0); |
| 187 | } |
| 188 | |
| 189 | static void test_socket_address_is(void) { |
| 190 | SocketAddress a; |
| 191 | |
| 192 | assert_se(socket_address_parse(&a, "192.168.1.1:8888") >= 0)do { if ((__builtin_expect(!!(!(socket_address_parse(&a, "192.168.1.1:8888" ) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ( "socket_address_parse(&a, \"192.168.1.1:8888\") >= 0") , "../src/test/test-socket-util.c", 192, __PRETTY_FUNCTION__) ; } while (0); |
| 193 | assert_se(socket_address_is(&a, "192.168.1.1:8888", SOCK_STREAM))do { if ((__builtin_expect(!!(!(socket_address_is(&a, "192.168.1.1:8888" , SOCK_STREAM))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("socket_address_is(&a, \"192.168.1.1:8888\", SOCK_STREAM)" ), "../src/test/test-socket-util.c", 193, __PRETTY_FUNCTION__ ); } while (0); |
| 194 | assert_se(!socket_address_is(&a, "route", SOCK_STREAM))do { if ((__builtin_expect(!!(!(!socket_address_is(&a, "route" , SOCK_STREAM))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("!socket_address_is(&a, \"route\", SOCK_STREAM)"), "../src/test/test-socket-util.c" , 194, __PRETTY_FUNCTION__); } while (0); |
| 195 | assert_se(!socket_address_is(&a, "192.168.1.1:8888", SOCK_RAW))do { if ((__builtin_expect(!!(!(!socket_address_is(&a, "192.168.1.1:8888" , SOCK_RAW))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!socket_address_is(&a, \"192.168.1.1:8888\", SOCK_RAW)" ), "../src/test/test-socket-util.c", 195, __PRETTY_FUNCTION__ ); } while (0); |
| 196 | } |
| 197 | |
| 198 | static void test_socket_address_is_netlink(void) { |
| 199 | SocketAddress a; |
| 200 | |
| 201 | assert_se(socket_address_parse_netlink(&a, "route 10") >= 0)do { if ((__builtin_expect(!!(!(socket_address_parse_netlink( &a, "route 10") >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("socket_address_parse_netlink(&a, \"route 10\") >= 0" ), "../src/test/test-socket-util.c", 201, __PRETTY_FUNCTION__ ); } while (0); |
| 202 | assert_se(socket_address_is_netlink(&a, "route 10"))do { if ((__builtin_expect(!!(!(socket_address_is_netlink(& a, "route 10"))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("socket_address_is_netlink(&a, \"route 10\")"), "../src/test/test-socket-util.c" , 202, __PRETTY_FUNCTION__); } while (0); |
| 203 | assert_se(!socket_address_is_netlink(&a, "192.168.1.1:8888"))do { if ((__builtin_expect(!!(!(!socket_address_is_netlink(& a, "192.168.1.1:8888"))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("!socket_address_is_netlink(&a, \"192.168.1.1:8888\")" ), "../src/test/test-socket-util.c", 203, __PRETTY_FUNCTION__ ); } while (0); |
| 204 | assert_se(!socket_address_is_netlink(&a, "route 1"))do { if ((__builtin_expect(!!(!(!socket_address_is_netlink(& a, "route 1"))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("!socket_address_is_netlink(&a, \"route 1\")"), "../src/test/test-socket-util.c" , 204, __PRETTY_FUNCTION__); } while (0); |
| 205 | } |
| 206 | |
| 207 | static void test_in_addr_is_null(void) { |
| 208 | |
| 209 | union in_addr_union i = {}; |
| 210 | |
| 211 | assert_se(in_addr_is_null(AF_INET, &i) == true)do { if ((__builtin_expect(!!(!(in_addr_is_null(2, &i) == 1)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("in_addr_is_null(AF_INET, &i) == true" ), "../src/test/test-socket-util.c", 211, __PRETTY_FUNCTION__ ); } while (0); |
| 212 | assert_se(in_addr_is_null(AF_INET6, &i) == true)do { if ((__builtin_expect(!!(!(in_addr_is_null(10, &i) == 1)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("in_addr_is_null(AF_INET6, &i) == true" ), "../src/test/test-socket-util.c", 212, __PRETTY_FUNCTION__ ); } while (0); |
| 213 | |
| 214 | i.in.s_addr = 0x1000000; |
| 215 | assert_se(in_addr_is_null(AF_INET, &i) == false)do { if ((__builtin_expect(!!(!(in_addr_is_null(2, &i) == 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("in_addr_is_null(AF_INET, &i) == false" ), "../src/test/test-socket-util.c", 215, __PRETTY_FUNCTION__ ); } while (0); |
| 216 | assert_se(in_addr_is_null(AF_INET6, &i) == false)do { if ((__builtin_expect(!!(!(in_addr_is_null(10, &i) == 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("in_addr_is_null(AF_INET6, &i) == false" ), "../src/test/test-socket-util.c", 216, __PRETTY_FUNCTION__ ); } while (0); |
| 217 | |
| 218 | assert_se(in_addr_is_null(-1, &i) == -EAFNOSUPPORT)do { if ((__builtin_expect(!!(!(in_addr_is_null(-1, &i) == -97)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("in_addr_is_null(-1, &i) == -EAFNOSUPPORT" ), "../src/test/test-socket-util.c", 218, __PRETTY_FUNCTION__ ); } while (0); |
| 219 | } |
| 220 | |
| 221 | static void test_in_addr_prefix_intersect_one(unsigned f, const char *a, unsigned apl, const char *b, unsigned bpl, int result) { |
| 222 | union in_addr_union ua, ub; |
| 223 | |
| 224 | assert_se(in_addr_from_string(f, a, &ua) >= 0)do { if ((__builtin_expect(!!(!(in_addr_from_string(f, a, & ua) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("in_addr_from_string(f, a, &ua) >= 0"), "../src/test/test-socket-util.c" , 224, __PRETTY_FUNCTION__); } while (0); |
| 225 | assert_se(in_addr_from_string(f, b, &ub) >= 0)do { if ((__builtin_expect(!!(!(in_addr_from_string(f, b, & ub) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("in_addr_from_string(f, b, &ub) >= 0"), "../src/test/test-socket-util.c" , 225, __PRETTY_FUNCTION__); } while (0); |
| 226 | |
| 227 | assert_se(in_addr_prefix_intersect(f, &ua, apl, &ub, bpl) == result)do { if ((__builtin_expect(!!(!(in_addr_prefix_intersect(f, & ua, apl, &ub, bpl) == result)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("in_addr_prefix_intersect(f, &ua, apl, &ub, bpl) == result" ), "../src/test/test-socket-util.c", 227, __PRETTY_FUNCTION__ ); } while (0); |
| 228 | } |
| 229 | |
| 230 | static void test_in_addr_prefix_intersect(void) { |
| 231 | |
| 232 | test_in_addr_prefix_intersect_one(AF_INET2, "255.255.255.255", 32, "255.255.255.254", 32, 0); |
| 233 | test_in_addr_prefix_intersect_one(AF_INET2, "255.255.255.255", 0, "255.255.255.255", 32, 1); |
| 234 | test_in_addr_prefix_intersect_one(AF_INET2, "0.0.0.0", 0, "47.11.8.15", 32, 1); |
| 235 | |
| 236 | test_in_addr_prefix_intersect_one(AF_INET2, "1.1.1.1", 24, "1.1.1.1", 24, 1); |
| 237 | test_in_addr_prefix_intersect_one(AF_INET2, "2.2.2.2", 24, "1.1.1.1", 24, 0); |
| 238 | |
| 239 | test_in_addr_prefix_intersect_one(AF_INET2, "1.1.1.1", 24, "1.1.1.127", 25, 1); |
| 240 | test_in_addr_prefix_intersect_one(AF_INET2, "1.1.1.1", 24, "1.1.1.127", 26, 1); |
| 241 | test_in_addr_prefix_intersect_one(AF_INET2, "1.1.1.1", 25, "1.1.1.127", 25, 1); |
| 242 | test_in_addr_prefix_intersect_one(AF_INET2, "1.1.1.1", 25, "1.1.1.255", 25, 0); |
| 243 | |
| 244 | test_in_addr_prefix_intersect_one(AF_INET610, "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", 128, "ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffe", 128, 0); |
| 245 | test_in_addr_prefix_intersect_one(AF_INET610, "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", 0, "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", 128, 1); |
| 246 | test_in_addr_prefix_intersect_one(AF_INET610, "::", 0, "beef:beef:beef:beef:beef:beef:beef:beef", 128, 1); |
| 247 | |
| 248 | test_in_addr_prefix_intersect_one(AF_INET610, "1::2", 64, "1::2", 64, 1); |
| 249 | test_in_addr_prefix_intersect_one(AF_INET610, "2::2", 64, "1::2", 64, 0); |
| 250 | |
| 251 | test_in_addr_prefix_intersect_one(AF_INET610, "1::1", 120, "1::007f", 121, 1); |
| 252 | test_in_addr_prefix_intersect_one(AF_INET610, "1::1", 120, "1::007f", 122, 1); |
| 253 | test_in_addr_prefix_intersect_one(AF_INET610, "1::1", 121, "1::007f", 121, 1); |
| 254 | test_in_addr_prefix_intersect_one(AF_INET610, "1::1", 121, "1::00ff", 121, 0); |
| 255 | } |
| 256 | |
| 257 | static void test_in_addr_prefix_next_one(unsigned f, const char *before, unsigned pl, const char *after) { |
| 258 | union in_addr_union ubefore, uafter, t; |
| 259 | |
| 260 | assert_se(in_addr_from_string(f, before, &ubefore) >= 0)do { if ((__builtin_expect(!!(!(in_addr_from_string(f, before , &ubefore) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("in_addr_from_string(f, before, &ubefore) >= 0"), "../src/test/test-socket-util.c" , 260, __PRETTY_FUNCTION__); } while (0); |
| 261 | |
| 262 | t = ubefore; |
| 263 | assert_se((in_addr_prefix_next(f, &t, pl) > 0) == !!after)do { if ((__builtin_expect(!!(!((in_addr_prefix_next(f, & t, pl) > 0) == !!after)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("(in_addr_prefix_next(f, &t, pl) > 0) == !!after"), "../src/test/test-socket-util.c", 263, __PRETTY_FUNCTION__); } while (0); |
| 264 | |
| 265 | if (after) { |
| 266 | assert_se(in_addr_from_string(f, after, &uafter) >= 0)do { if ((__builtin_expect(!!(!(in_addr_from_string(f, after, &uafter) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("in_addr_from_string(f, after, &uafter) >= 0"), "../src/test/test-socket-util.c" , 266, __PRETTY_FUNCTION__); } while (0); |
| 267 | assert_se(in_addr_equal(f, &t, &uafter) > 0)do { if ((__builtin_expect(!!(!(in_addr_equal(f, &t, & uafter) > 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("in_addr_equal(f, &t, &uafter) > 0"), "../src/test/test-socket-util.c" , 267, __PRETTY_FUNCTION__); } while (0); |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | static void test_in_addr_prefix_next(void) { |
| 272 | |
| 273 | test_in_addr_prefix_next_one(AF_INET2, "192.168.0.0", 24, "192.168.1.0"); |
| 274 | test_in_addr_prefix_next_one(AF_INET2, "192.168.0.0", 16, "192.169.0.0"); |
| 275 | test_in_addr_prefix_next_one(AF_INET2, "192.168.0.0", 20, "192.168.16.0"); |
| 276 | |
| 277 | test_in_addr_prefix_next_one(AF_INET2, "0.0.0.0", 32, "0.0.0.1"); |
| 278 | test_in_addr_prefix_next_one(AF_INET2, "255.255.255.255", 32, NULL((void*)0)); |
| 279 | test_in_addr_prefix_next_one(AF_INET2, "255.255.255.0", 24, NULL((void*)0)); |
| 280 | |
| 281 | test_in_addr_prefix_next_one(AF_INET610, "4400::", 128, "4400::0001"); |
| 282 | test_in_addr_prefix_next_one(AF_INET610, "4400::", 120, "4400::0100"); |
| 283 | test_in_addr_prefix_next_one(AF_INET610, "4400::", 127, "4400::0002"); |
| 284 | test_in_addr_prefix_next_one(AF_INET610, "4400::", 8, "4500::"); |
| 285 | test_in_addr_prefix_next_one(AF_INET610, "4400::", 7, "4600::"); |
| 286 | |
| 287 | test_in_addr_prefix_next_one(AF_INET610, "::", 128, "::1"); |
| 288 | |
| 289 | test_in_addr_prefix_next_one(AF_INET610, "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", 128, NULL((void*)0)); |
| 290 | test_in_addr_prefix_next_one(AF_INET610, "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ff00", 120, NULL((void*)0)); |
| 291 | |
| 292 | } |
| 293 | |
| 294 | static void test_in_addr_to_string_one(int f, const char *addr) { |
| 295 | union in_addr_union ua; |
| 296 | _cleanup_free___attribute__((cleanup(freep))) char *r = NULL((void*)0); |
| 297 | |
| 298 | assert_se(in_addr_from_string(f, addr, &ua) >= 0)do { if ((__builtin_expect(!!(!(in_addr_from_string(f, addr, & ua) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("in_addr_from_string(f, addr, &ua) >= 0"), "../src/test/test-socket-util.c" , 298, __PRETTY_FUNCTION__); } while (0); |
| 299 | assert_se(in_addr_to_string(f, &ua, &r) >= 0)do { if ((__builtin_expect(!!(!(in_addr_to_string(f, &ua, &r) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("in_addr_to_string(f, &ua, &r) >= 0"), "../src/test/test-socket-util.c" , 299, __PRETTY_FUNCTION__); } while (0); |
| 300 | printf("test_in_addr_to_string_one: %s == %s\n", addr, r); |
| 301 | assert_se(streq(addr, r))do { if ((__builtin_expect(!!(!((strcmp((addr),(r)) == 0))),0 ))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(addr, r)" ), "../src/test/test-socket-util.c", 301, __PRETTY_FUNCTION__ ); } while (0); |
| 302 | } |
| 303 | |
| 304 | static void test_in_addr_to_string(void) { |
| 305 | test_in_addr_to_string_one(AF_INET2, "192.168.0.1"); |
| 306 | test_in_addr_to_string_one(AF_INET2, "10.11.12.13"); |
| 307 | test_in_addr_to_string_one(AF_INET610, "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"); |
| 308 | test_in_addr_to_string_one(AF_INET610, "::1"); |
| 309 | test_in_addr_to_string_one(AF_INET610, "fe80::"); |
| 310 | } |
| 311 | |
| 312 | static void test_in_addr_ifindex_to_string_one(int f, const char *a, int ifindex, const char *b) { |
| 313 | _cleanup_free___attribute__((cleanup(freep))) char *r = NULL((void*)0); |
| 314 | union in_addr_union ua, uuaa; |
| 315 | int ff, ifindex2; |
| 316 | |
| 317 | assert_se(in_addr_from_string(f, a, &ua) >= 0)do { if ((__builtin_expect(!!(!(in_addr_from_string(f, a, & ua) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("in_addr_from_string(f, a, &ua) >= 0"), "../src/test/test-socket-util.c" , 317, __PRETTY_FUNCTION__); } while (0); |
| 318 | assert_se(in_addr_ifindex_to_string(f, &ua, ifindex, &r) >= 0)do { if ((__builtin_expect(!!(!(in_addr_ifindex_to_string(f, & ua, ifindex, &r) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("in_addr_ifindex_to_string(f, &ua, ifindex, &r) >= 0" ), "../src/test/test-socket-util.c", 318, __PRETTY_FUNCTION__ ); } while (0); |
| 319 | printf("test_in_addr_ifindex_to_string_one: %s == %s\n", b, r); |
| 320 | assert_se(streq(b, r))do { if ((__builtin_expect(!!(!((strcmp((b),(r)) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(b, r)"), "../src/test/test-socket-util.c" , 320, __PRETTY_FUNCTION__); } while (0); |
| 321 | |
| 322 | assert_se(in_addr_ifindex_from_string_auto(b, &ff, &uuaa, &ifindex2) >= 0)do { if ((__builtin_expect(!!(!(in_addr_ifindex_from_string_auto (b, &ff, &uuaa, &ifindex2) >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("in_addr_ifindex_from_string_auto(b, &ff, &uuaa, &ifindex2) >= 0" ), "../src/test/test-socket-util.c", 322, __PRETTY_FUNCTION__ ); } while (0); |
| 323 | assert_se(ff == f)do { if ((__builtin_expect(!!(!(ff == f)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("ff == f"), "../src/test/test-socket-util.c" , 323, __PRETTY_FUNCTION__); } while (0); |
| 324 | assert_se(in_addr_equal(f, &ua, &uuaa))do { if ((__builtin_expect(!!(!(in_addr_equal(f, &ua, & uuaa))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("in_addr_equal(f, &ua, &uuaa)" ), "../src/test/test-socket-util.c", 324, __PRETTY_FUNCTION__ ); } while (0); |
| 325 | assert_se(ifindex2 == ifindex || ifindex2 == 0)do { if ((__builtin_expect(!!(!(ifindex2 == ifindex || ifindex2 == 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("ifindex2 == ifindex || ifindex2 == 0" ), "../src/test/test-socket-util.c", 325, __PRETTY_FUNCTION__ ); } while (0); |
| 326 | } |
| 327 | |
| 328 | static void test_in_addr_ifindex_to_string(void) { |
| 329 | test_in_addr_ifindex_to_string_one(AF_INET2, "192.168.0.1", 7, "192.168.0.1"); |
| 330 | test_in_addr_ifindex_to_string_one(AF_INET2, "10.11.12.13", 9, "10.11.12.13"); |
| 331 | test_in_addr_ifindex_to_string_one(AF_INET610, "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", 10, "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"); |
| 332 | test_in_addr_ifindex_to_string_one(AF_INET610, "::1", 11, "::1"); |
| 333 | test_in_addr_ifindex_to_string_one(AF_INET610, "fe80::", 12, "fe80::%12"); |
| 334 | test_in_addr_ifindex_to_string_one(AF_INET610, "fe80::", 0, "fe80::"); |
| 335 | test_in_addr_ifindex_to_string_one(AF_INET610, "fe80::14", 12, "fe80::14%12"); |
| 336 | test_in_addr_ifindex_to_string_one(AF_INET610, "fe80::15", -7, "fe80::15"); |
| 337 | test_in_addr_ifindex_to_string_one(AF_INET610, "fe80::16", LOOPBACK_IFINDEX1, "fe80::16%1"); |
| 338 | } |
| 339 | |
| 340 | static void test_in_addr_ifindex_from_string_auto(void) { |
| 341 | int family, ifindex; |
| 342 | union in_addr_union ua; |
| 343 | |
| 344 | /* Most in_addr_ifindex_from_string_auto() invocations have already been tested above, but let's test some more */ |
| 345 | |
| 346 | assert_se(in_addr_ifindex_from_string_auto("fe80::17", &family, &ua, &ifindex) >= 0)do { if ((__builtin_expect(!!(!(in_addr_ifindex_from_string_auto ("fe80::17", &family, &ua, &ifindex) >= 0)),0) )) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("in_addr_ifindex_from_string_auto(\"fe80::17\", &family, &ua, &ifindex) >= 0" ), "../src/test/test-socket-util.c", 346, __PRETTY_FUNCTION__ ); } while (0); |
| 347 | assert_se(family == AF_INET6)do { if ((__builtin_expect(!!(!(family == 10)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("family == AF_INET6"), "../src/test/test-socket-util.c" , 347, __PRETTY_FUNCTION__); } while (0); |
| 348 | assert_se(ifindex == 0)do { if ((__builtin_expect(!!(!(ifindex == 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("ifindex == 0"), "../src/test/test-socket-util.c" , 348, __PRETTY_FUNCTION__); } while (0); |
| 349 | |
| 350 | assert_se(in_addr_ifindex_from_string_auto("fe80::18%19", &family, &ua, &ifindex) >= 0)do { if ((__builtin_expect(!!(!(in_addr_ifindex_from_string_auto ("fe80::18%19", &family, &ua, &ifindex) >= 0)) ,0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("in_addr_ifindex_from_string_auto(\"fe80::18%19\", &family, &ua, &ifindex) >= 0" ), "../src/test/test-socket-util.c", 350, __PRETTY_FUNCTION__ ); } while (0); |
| 351 | assert_se(family == AF_INET6)do { if ((__builtin_expect(!!(!(family == 10)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("family == AF_INET6"), "../src/test/test-socket-util.c" , 351, __PRETTY_FUNCTION__); } while (0); |
| 352 | assert_se(ifindex == 19)do { if ((__builtin_expect(!!(!(ifindex == 19)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("ifindex == 19"), "../src/test/test-socket-util.c" , 352, __PRETTY_FUNCTION__); } while (0); |
| 353 | |
| 354 | assert_se(in_addr_ifindex_from_string_auto("fe80::18%lo", &family, &ua, &ifindex) >= 0)do { if ((__builtin_expect(!!(!(in_addr_ifindex_from_string_auto ("fe80::18%lo", &family, &ua, &ifindex) >= 0)) ,0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("in_addr_ifindex_from_string_auto(\"fe80::18%lo\", &family, &ua, &ifindex) >= 0" ), "../src/test/test-socket-util.c", 354, __PRETTY_FUNCTION__ ); } while (0); |
| 355 | assert_se(family == AF_INET6)do { if ((__builtin_expect(!!(!(family == 10)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("family == AF_INET6"), "../src/test/test-socket-util.c" , 355, __PRETTY_FUNCTION__); } while (0); |
| 356 | assert_se(ifindex == LOOPBACK_IFINDEX)do { if ((__builtin_expect(!!(!(ifindex == 1)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("ifindex == LOOPBACK_IFINDEX"), "../src/test/test-socket-util.c" , 356, __PRETTY_FUNCTION__); } while (0); |
| 357 | |
| 358 | assert_se(in_addr_ifindex_from_string_auto("fe80::19%thisinterfacecantexist", &family, &ua, &ifindex) == -ENODEV)do { if ((__builtin_expect(!!(!(in_addr_ifindex_from_string_auto ("fe80::19%thisinterfacecantexist", &family, &ua, & ifindex) == -19)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("in_addr_ifindex_from_string_auto(\"fe80::19%thisinterfacecantexist\", &family, &ua, &ifindex) == -ENODEV" ), "../src/test/test-socket-util.c", 358, __PRETTY_FUNCTION__ ); } while (0); |
| 359 | } |
| 360 | |
| 361 | static void test_sockaddr_equal(void) { |
| 362 | union sockaddr_union a = { |
| 363 | .in.sin_family = AF_INET2, |
| 364 | .in.sin_port = 0, |
| 365 | .in.sin_addr.s_addr = htobe32(INADDR_ANY)__bswap_32 (((in_addr_t) 0x00000000)), |
| 366 | }; |
| 367 | union sockaddr_union b = { |
| 368 | .in.sin_family = AF_INET2, |
| 369 | .in.sin_port = 0, |
| 370 | .in.sin_addr.s_addr = htobe32(INADDR_ANY)__bswap_32 (((in_addr_t) 0x00000000)), |
| 371 | }; |
| 372 | union sockaddr_union c = { |
| 373 | .in.sin_family = AF_INET2, |
| 374 | .in.sin_port = 0, |
| 375 | .in.sin_addr.s_addr = htobe32(1234)__bswap_32 (1234), |
| 376 | }; |
| 377 | union sockaddr_union d = { |
| 378 | .in6.sin6_family = AF_INET610, |
| 379 | .in6.sin6_port = 0, |
| 380 | .in6.sin6_addr = IN6ADDR_ANY_INIT{ { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } }, |
| 381 | }; |
| 382 | union sockaddr_union e = { |
| 383 | .vm.svm_family = AF_VSOCK40, |
| 384 | .vm.svm_port = 0, |
| 385 | .vm.svm_cid = VMADDR_CID_ANY-1U, |
| 386 | }; |
| 387 | assert_se(sockaddr_equal(&a, &a))do { if ((__builtin_expect(!!(!(sockaddr_equal(&a, &a ))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("sockaddr_equal(&a, &a)" ), "../src/test/test-socket-util.c", 387, __PRETTY_FUNCTION__ ); } while (0); |
| 388 | assert_se(sockaddr_equal(&a, &b))do { if ((__builtin_expect(!!(!(sockaddr_equal(&a, &b ))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("sockaddr_equal(&a, &b)" ), "../src/test/test-socket-util.c", 388, __PRETTY_FUNCTION__ ); } while (0); |
| 389 | assert_se(sockaddr_equal(&d, &d))do { if ((__builtin_expect(!!(!(sockaddr_equal(&d, &d ))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("sockaddr_equal(&d, &d)" ), "../src/test/test-socket-util.c", 389, __PRETTY_FUNCTION__ ); } while (0); |
| 390 | assert_se(sockaddr_equal(&e, &e))do { if ((__builtin_expect(!!(!(sockaddr_equal(&e, &e ))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("sockaddr_equal(&e, &e)" ), "../src/test/test-socket-util.c", 390, __PRETTY_FUNCTION__ ); } while (0); |
| 391 | assert_se(!sockaddr_equal(&a, &c))do { if ((__builtin_expect(!!(!(!sockaddr_equal(&a, & c))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!sockaddr_equal(&a, &c)" ), "../src/test/test-socket-util.c", 391, __PRETTY_FUNCTION__ ); } while (0); |
| 392 | assert_se(!sockaddr_equal(&b, &c))do { if ((__builtin_expect(!!(!(!sockaddr_equal(&b, & c))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!sockaddr_equal(&b, &c)" ), "../src/test/test-socket-util.c", 392, __PRETTY_FUNCTION__ ); } while (0); |
| 393 | assert_se(!sockaddr_equal(&a, &e))do { if ((__builtin_expect(!!(!(!sockaddr_equal(&a, & e))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!sockaddr_equal(&a, &e)" ), "../src/test/test-socket-util.c", 393, __PRETTY_FUNCTION__ ); } while (0); |
| 394 | } |
| 395 | |
| 396 | static void test_sockaddr_un_len(void) { |
| 397 | static const struct sockaddr_un fs = { |
| 398 | .sun_family = AF_UNIX1, |
| 399 | .sun_path = "/foo/bar/waldo", |
| 400 | }; |
| 401 | |
| 402 | static const struct sockaddr_un abstract = { |
| 403 | .sun_family = AF_UNIX1, |
| 404 | .sun_path = "\0foobar", |
| 405 | }; |
| 406 | |
| 407 | assert_se(SOCKADDR_UN_LEN(fs) == offsetof(struct sockaddr_un, sun_path) + strlen(fs.sun_path))do { if ((__builtin_expect(!!(!(({ const struct sockaddr_un * _sa = &(fs); do { if ((__builtin_expect(!!(!(_sa->sun_family == 1)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("_sa->sun_family == AF_UNIX" ), "../src/test/test-socket-util.c", 407, __PRETTY_FUNCTION__ ); } while (0); __builtin_offsetof(struct sockaddr_un, sun_path ) + (_sa->sun_path[0] == 0 ? 1 + strnlen(_sa->sun_path+ 1, sizeof(_sa->sun_path)-1) : strnlen(_sa->sun_path, sizeof (_sa->sun_path))); }) == __builtin_offsetof(struct sockaddr_un , sun_path) + strlen(fs.sun_path))),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("SOCKADDR_UN_LEN(fs) == offsetof(struct sockaddr_un, sun_path) + strlen(fs.sun_path)" ), "../src/test/test-socket-util.c", 407, __PRETTY_FUNCTION__ ); } while (0); |
| 408 | assert_se(SOCKADDR_UN_LEN(abstract) == offsetof(struct sockaddr_un, sun_path) + 1 + strlen(abstract.sun_path + 1))do { if ((__builtin_expect(!!(!(({ const struct sockaddr_un * _sa = &(abstract); do { if ((__builtin_expect(!!(!(_sa-> sun_family == 1)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("_sa->sun_family == AF_UNIX"), "../src/test/test-socket-util.c" , 408, __PRETTY_FUNCTION__); } while (0); __builtin_offsetof( struct sockaddr_un, sun_path) + (_sa->sun_path[0] == 0 ? 1 + strnlen(_sa->sun_path+1, sizeof(_sa->sun_path)-1) : strnlen (_sa->sun_path, sizeof(_sa->sun_path))); }) == __builtin_offsetof (struct sockaddr_un, sun_path) + 1 + strlen(abstract.sun_path + 1))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("SOCKADDR_UN_LEN(abstract) == offsetof(struct sockaddr_un, sun_path) + 1 + strlen(abstract.sun_path + 1)" ), "../src/test/test-socket-util.c", 408, __PRETTY_FUNCTION__ ); } while (0); |
| 409 | } |
| 410 | |
| 411 | static void test_in_addr_is_multicast(void) { |
| 412 | union in_addr_union a, b; |
| 413 | int f; |
| 414 | |
| 415 | assert_se(in_addr_from_string_auto("192.168.3.11", &f, &a) >= 0)do { if ((__builtin_expect(!!(!(in_addr_from_string_auto("192.168.3.11" , &f, &a) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("in_addr_from_string_auto(\"192.168.3.11\", &f, &a) >= 0" ), "../src/test/test-socket-util.c", 415, __PRETTY_FUNCTION__ ); } while (0); |
| 416 | assert_se(in_addr_is_multicast(f, &a) == 0)do { if ((__builtin_expect(!!(!(in_addr_is_multicast(f, & a) == 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("in_addr_is_multicast(f, &a) == 0" ), "../src/test/test-socket-util.c", 416, __PRETTY_FUNCTION__ ); } while (0); |
| 417 | |
| 418 | assert_se(in_addr_from_string_auto("224.0.0.1", &f, &a) >= 0)do { if ((__builtin_expect(!!(!(in_addr_from_string_auto("224.0.0.1" , &f, &a) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("in_addr_from_string_auto(\"224.0.0.1\", &f, &a) >= 0" ), "../src/test/test-socket-util.c", 418, __PRETTY_FUNCTION__ ); } while (0); |
| 419 | assert_se(in_addr_is_multicast(f, &a) == 1)do { if ((__builtin_expect(!!(!(in_addr_is_multicast(f, & a) == 1)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("in_addr_is_multicast(f, &a) == 1" ), "../src/test/test-socket-util.c", 419, __PRETTY_FUNCTION__ ); } while (0); |
| 420 | |
| 421 | assert_se(in_addr_from_string_auto("FF01:0:0:0:0:0:0:1", &f, &b) >= 0)do { if ((__builtin_expect(!!(!(in_addr_from_string_auto("FF01:0:0:0:0:0:0:1" , &f, &b) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("in_addr_from_string_auto(\"FF01:0:0:0:0:0:0:1\", &f, &b) >= 0" ), "../src/test/test-socket-util.c", 421, __PRETTY_FUNCTION__ ); } while (0); |
| 422 | assert_se(in_addr_is_multicast(f, &b) == 1)do { if ((__builtin_expect(!!(!(in_addr_is_multicast(f, & b) == 1)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("in_addr_is_multicast(f, &b) == 1" ), "../src/test/test-socket-util.c", 422, __PRETTY_FUNCTION__ ); } while (0); |
| 423 | |
| 424 | assert_se(in_addr_from_string_auto("2001:db8::c:69b:aeff:fe53:743e", &f, &b) >= 0)do { if ((__builtin_expect(!!(!(in_addr_from_string_auto("2001:db8::c:69b:aeff:fe53:743e" , &f, &b) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("in_addr_from_string_auto(\"2001:db8::c:69b:aeff:fe53:743e\", &f, &b) >= 0" ), "../src/test/test-socket-util.c", 424, __PRETTY_FUNCTION__ ); } while (0); |
| 425 | assert_se(in_addr_is_multicast(f, &b) == 0)do { if ((__builtin_expect(!!(!(in_addr_is_multicast(f, & b) == 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("in_addr_is_multicast(f, &b) == 0" ), "../src/test/test-socket-util.c", 425, __PRETTY_FUNCTION__ ); } while (0); |
| 426 | } |
| 427 | |
| 428 | static void test_getpeercred_getpeergroups(void) { |
| 429 | int r; |
| 430 | |
| 431 | r = safe_fork("(getpeercred)", FORK_DEATHSIG|FORK_LOG|FORK_WAIT, NULL((void*)0)); |
| 432 | assert_se(r >= 0)do { if ((__builtin_expect(!!(!(r >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r >= 0"), "../src/test/test-socket-util.c" , 432, __PRETTY_FUNCTION__); } while (0); |
| 433 | |
| 434 | if (r == 0) { |
| 435 | static const gid_t gids[] = { 3, 4, 5, 6, 7 }; |
| 436 | gid_t *test_gids; |
| 437 | size_t n_test_gids; |
| 438 | uid_t test_uid; |
| 439 | gid_t test_gid; |
| 440 | struct ucred ucred; |
| 441 | int pair[2]; |
| 442 | |
| 443 | if (geteuid() == 0) { |
| 444 | test_uid = 1; |
| 445 | test_gid = 2; |
| 446 | test_gids = (gid_t*) gids; |
| 447 | n_test_gids = ELEMENTSOF(gids)__extension__ (__builtin_choose_expr( !__builtin_types_compatible_p (typeof(gids), typeof(&*(gids))), sizeof(gids)/sizeof((gids )[0]), ((void)0))); |
| 448 | |
| 449 | assert_se(setgroups(n_test_gids, test_gids) >= 0)do { if ((__builtin_expect(!!(!(setgroups(n_test_gids, test_gids ) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ( "setgroups(n_test_gids, test_gids) >= 0"), "../src/test/test-socket-util.c" , 449, __PRETTY_FUNCTION__); } while (0); |
| 450 | assert_se(setresgid(test_gid, test_gid, test_gid) >= 0)do { if ((__builtin_expect(!!(!(setresgid(test_gid, test_gid, test_gid) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("setresgid(test_gid, test_gid, test_gid) >= 0"), "../src/test/test-socket-util.c" , 450, __PRETTY_FUNCTION__); } while (0); |
| 451 | assert_se(setresuid(test_uid, test_uid, test_uid) >= 0)do { if ((__builtin_expect(!!(!(setresuid(test_uid, test_uid, test_uid) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("setresuid(test_uid, test_uid, test_uid) >= 0"), "../src/test/test-socket-util.c" , 451, __PRETTY_FUNCTION__); } while (0); |
| 452 | |
| 453 | } else { |
| 454 | long ngroups_max; |
| 455 | |
| 456 | test_uid = getuid(); |
| 457 | test_gid = getgid(); |
| 458 | |
| 459 | ngroups_max = sysconf(_SC_NGROUPS_MAX_SC_NGROUPS_MAX); |
| 460 | assert(ngroups_max > 0)do { if ((__builtin_expect(!!(!(ngroups_max > 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("ngroups_max > 0"), "../src/test/test-socket-util.c" , 460, __PRETTY_FUNCTION__); } while (0); |
| 461 | |
| 462 | test_gids = newa(gid_t, ngroups_max)({ do { if ((__builtin_expect(!!(!(!size_multiply_overflow(sizeof (gid_t), ngroups_max))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("!size_multiply_overflow(sizeof(gid_t), ngroups_max)"), "../src/test/test-socket-util.c" , 462, __PRETTY_FUNCTION__); } while (0); (gid_t*) __builtin_alloca (sizeof(gid_t)*(ngroups_max)); }); |
| 463 | |
| 464 | r = getgroups(ngroups_max, test_gids); |
| 465 | assert_se(r >= 0)do { if ((__builtin_expect(!!(!(r >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r >= 0"), "../src/test/test-socket-util.c" , 465, __PRETTY_FUNCTION__); } while (0); |
| 466 | n_test_gids = (size_t) r; |
| 467 | } |
| 468 | |
| 469 | assert_se(socketpair(AF_UNIX, SOCK_STREAM, 0, pair) >= 0)do { if ((__builtin_expect(!!(!(socketpair(1, SOCK_STREAM, 0, pair) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("socketpair(AF_UNIX, SOCK_STREAM, 0, pair) >= 0"), "../src/test/test-socket-util.c" , 469, __PRETTY_FUNCTION__); } while (0); |
| 470 | |
| 471 | assert_se(getpeercred(pair[0], &ucred) >= 0)do { if ((__builtin_expect(!!(!(getpeercred(pair[0], &ucred ) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ( "getpeercred(pair[0], &ucred) >= 0"), "../src/test/test-socket-util.c" , 471, __PRETTY_FUNCTION__); } while (0); |
| 472 | |
| 473 | assert_se(ucred.uid == test_uid)do { if ((__builtin_expect(!!(!(ucred.uid == test_uid)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("ucred.uid == test_uid"), "../src/test/test-socket-util.c" , 473, __PRETTY_FUNCTION__); } while (0); |
| 474 | assert_se(ucred.gid == test_gid)do { if ((__builtin_expect(!!(!(ucred.gid == test_gid)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("ucred.gid == test_gid"), "../src/test/test-socket-util.c" , 474, __PRETTY_FUNCTION__); } while (0); |
| 475 | assert_se(ucred.pid == getpid_cached())do { if ((__builtin_expect(!!(!(ucred.pid == getpid_cached()) ),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("ucred.pid == getpid_cached()" ), "../src/test/test-socket-util.c", 475, __PRETTY_FUNCTION__ ); } while (0); |
| 476 | |
| 477 | { |
| 478 | _cleanup_free___attribute__((cleanup(freep))) gid_t *peer_groups = NULL((void*)0); |
| 479 | |
| 480 | r = getpeergroups(pair[0], &peer_groups); |
| 481 | assert_se(r >= 0 || IN_SET(r, -EOPNOTSUPP, -ENOPROTOOPT))do { if ((__builtin_expect(!!(!(r >= 0 || ({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended [20 - sizeof((int[]){-95, -92})/sizeof(int)]; switch(r) { case -95: case -92: _found = 1; break; default: break; } _found; } ))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("r >= 0 || IN_SET(r, -EOPNOTSUPP, -ENOPROTOOPT)" ), "../src/test/test-socket-util.c", 481, __PRETTY_FUNCTION__ ); } while (0); |
| 482 | |
| 483 | if (r >= 0) { |
| 484 | assert_se((size_t) r == n_test_gids)do { if ((__builtin_expect(!!(!((size_t) r == n_test_gids)),0 ))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("(size_t) r == n_test_gids" ), "../src/test/test-socket-util.c", 484, __PRETTY_FUNCTION__ ); } while (0); |
| 485 | assert_se(memcmp(peer_groups, test_gids, sizeof(gid_t) * n_test_gids) == 0)do { if ((__builtin_expect(!!(!(memcmp(peer_groups, test_gids , sizeof(gid_t) * n_test_gids) == 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("memcmp(peer_groups, test_gids, sizeof(gid_t) * n_test_gids) == 0" ), "../src/test/test-socket-util.c", 485, __PRETTY_FUNCTION__ ); } while (0); |
| 486 | } |
| 487 | } |
| 488 | |
| 489 | safe_close_pair(pair); |
| 490 | _exit(EXIT_SUCCESS0); |
| 491 | } |
| 492 | } |
| 493 | |
| 494 | static void test_passfd_read(void) { |
| 495 | static const char file_contents[] = "test contents for passfd"; |
| 496 | _cleanup_close_pair___attribute__((cleanup(close_pairp))) int pair[2] = { -1, -1 }; |
| 497 | int r; |
| 498 | |
| 499 | assert_se(socketpair(AF_UNIX, SOCK_DGRAM, 0, pair) >= 0)do { if ((__builtin_expect(!!(!(socketpair(1, SOCK_DGRAM, 0, pair ) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ( "socketpair(AF_UNIX, SOCK_DGRAM, 0, pair) >= 0"), "../src/test/test-socket-util.c" , 499, __PRETTY_FUNCTION__); } while (0); |
| 500 | |
| 501 | r = safe_fork("(passfd_read)", FORK_DEATHSIG|FORK_LOG|FORK_WAIT, NULL((void*)0)); |
| 502 | assert_se(r >= 0)do { if ((__builtin_expect(!!(!(r >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r >= 0"), "../src/test/test-socket-util.c" , 502, __PRETTY_FUNCTION__); } while (0); |
| 503 | |
| 504 | if (r == 0) { |
| 505 | /* Child */ |
| 506 | char tmpfile[] = "/tmp/test-socket-util-passfd-read-XXXXXX"; |
| 507 | _cleanup_close___attribute__((cleanup(closep))) int tmpfd = -1; |
| 508 | |
| 509 | pair[0] = safe_close(pair[0]); |
| 510 | |
| 511 | tmpfd = mkostemp_safe(tmpfile); |
| 512 | assert_se(tmpfd >= 0)do { if ((__builtin_expect(!!(!(tmpfd >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("tmpfd >= 0"), "../src/test/test-socket-util.c" , 512, __PRETTY_FUNCTION__); } while (0); |
| 513 | assert_se(write(tmpfd, file_contents, strlen(file_contents)) == (ssize_t) strlen(file_contents))do { if ((__builtin_expect(!!(!(write(tmpfd, file_contents, strlen (file_contents)) == (ssize_t) strlen(file_contents))),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("write(tmpfd, file_contents, strlen(file_contents)) == (ssize_t) strlen(file_contents)" ), "../src/test/test-socket-util.c", 513, __PRETTY_FUNCTION__ ); } while (0); |
| 514 | tmpfd = safe_close(tmpfd); |
| 515 | |
| 516 | tmpfd = open(tmpfile, O_RDONLY00); |
| 517 | assert_se(tmpfd >= 0)do { if ((__builtin_expect(!!(!(tmpfd >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("tmpfd >= 0"), "../src/test/test-socket-util.c" , 517, __PRETTY_FUNCTION__); } while (0); |
| 518 | assert_se(unlink(tmpfile) == 0)do { if ((__builtin_expect(!!(!(unlink(tmpfile) == 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("unlink(tmpfile) == 0"), "../src/test/test-socket-util.c" , 518, __PRETTY_FUNCTION__); } while (0); |
| 519 | |
| 520 | assert_se(send_one_fd(pair[1], tmpfd, MSG_DONTWAIT) == 0)do { if ((__builtin_expect(!!(!(send_one_fd_iov_sa(pair[1], tmpfd , ((void*)0), 0, ((void*)0), 0, MSG_DONTWAIT) == 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("send_one_fd(pair[1], tmpfd, MSG_DONTWAIT) == 0" ), "../src/test/test-socket-util.c", 520, __PRETTY_FUNCTION__ ); } while (0); |
| 521 | _exit(EXIT_SUCCESS0); |
| 522 | } |
| 523 | |
| 524 | /* Parent */ |
| 525 | char buf[64]; |
| 526 | struct iovec iov = IOVEC_INIT(buf, sizeof(buf)-1){ .iov_base = (buf), .iov_len = (sizeof(buf)-1) }; |
| 527 | _cleanup_close___attribute__((cleanup(closep))) int fd = -1; |
| 528 | |
| 529 | pair[1] = safe_close(pair[1]); |
| 530 | |
| 531 | assert_se(receive_one_fd_iov(pair[0], &iov, 1, MSG_DONTWAIT, &fd) == 0)do { if ((__builtin_expect(!!(!(receive_one_fd_iov(pair[0], & iov, 1, MSG_DONTWAIT, &fd) == 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("receive_one_fd_iov(pair[0], &iov, 1, MSG_DONTWAIT, &fd) == 0" ), "../src/test/test-socket-util.c", 531, __PRETTY_FUNCTION__ ); } while (0); |
| 532 | |
| 533 | assert_se(fd >= 0)do { if ((__builtin_expect(!!(!(fd >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("fd >= 0"), "../src/test/test-socket-util.c" , 533, __PRETTY_FUNCTION__); } while (0); |
| 534 | r = read(fd, buf, sizeof(buf)-1); |
| 535 | assert_se(r >= 0)do { if ((__builtin_expect(!!(!(r >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r >= 0"), "../src/test/test-socket-util.c" , 535, __PRETTY_FUNCTION__); } while (0); |
| 536 | buf[r] = 0; |
| 537 | assert_se(streq(buf, file_contents))do { if ((__builtin_expect(!!(!((strcmp((buf),(file_contents) ) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(buf, file_contents)" ), "../src/test/test-socket-util.c", 537, __PRETTY_FUNCTION__ ); } while (0); |
| 538 | } |
| 539 | |
| 540 | static void test_passfd_contents_read(void) { |
| 541 | _cleanup_close_pair___attribute__((cleanup(close_pairp))) int pair[2] = { -1, -1 }; |
| 542 | static const char file_contents[] = "test contents in the file"; |
| 543 | static const char wire_contents[] = "test contents on the wire"; |
| 544 | int r; |
| 545 | |
| 546 | assert_se(socketpair(AF_UNIX, SOCK_DGRAM, 0, pair) >= 0)do { if ((__builtin_expect(!!(!(socketpair(1, SOCK_DGRAM, 0, pair ) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ( "socketpair(AF_UNIX, SOCK_DGRAM, 0, pair) >= 0"), "../src/test/test-socket-util.c" , 546, __PRETTY_FUNCTION__); } while (0); |
| 547 | |
| 548 | r = safe_fork("(passfd_contents_read)", FORK_DEATHSIG|FORK_LOG|FORK_WAIT, NULL((void*)0)); |
| 549 | assert_se(r >= 0)do { if ((__builtin_expect(!!(!(r >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r >= 0"), "../src/test/test-socket-util.c" , 549, __PRETTY_FUNCTION__); } while (0); |
| 550 | |
| 551 | if (r == 0) { |
| 552 | /* Child */ |
| 553 | struct iovec iov = IOVEC_INIT_STRING(wire_contents){ .iov_base = ((char*) wire_contents), .iov_len = (strlen(wire_contents )) }; |
| 554 | char tmpfile[] = "/tmp/test-socket-util-passfd-contents-read-XXXXXX"; |
| 555 | _cleanup_close___attribute__((cleanup(closep))) int tmpfd = -1; |
| 556 | |
| 557 | pair[0] = safe_close(pair[0]); |
| 558 | |
| 559 | tmpfd = mkostemp_safe(tmpfile); |
| 560 | assert_se(tmpfd >= 0)do { if ((__builtin_expect(!!(!(tmpfd >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("tmpfd >= 0"), "../src/test/test-socket-util.c" , 560, __PRETTY_FUNCTION__); } while (0); |
| 561 | assert_se(write(tmpfd, file_contents, strlen(file_contents)) == (ssize_t) strlen(file_contents))do { if ((__builtin_expect(!!(!(write(tmpfd, file_contents, strlen (file_contents)) == (ssize_t) strlen(file_contents))),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("write(tmpfd, file_contents, strlen(file_contents)) == (ssize_t) strlen(file_contents)" ), "../src/test/test-socket-util.c", 561, __PRETTY_FUNCTION__ ); } while (0); |
| 562 | tmpfd = safe_close(tmpfd); |
Value stored to 'tmpfd' is never read | |
| 563 | |
| 564 | tmpfd = open(tmpfile, O_RDONLY00); |
| 565 | assert_se(tmpfd >= 0)do { if ((__builtin_expect(!!(!(tmpfd >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("tmpfd >= 0"), "../src/test/test-socket-util.c" , 565, __PRETTY_FUNCTION__); } while (0); |
| 566 | assert_se(unlink(tmpfile) == 0)do { if ((__builtin_expect(!!(!(unlink(tmpfile) == 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("unlink(tmpfile) == 0"), "../src/test/test-socket-util.c" , 566, __PRETTY_FUNCTION__); } while (0); |
| 567 | |
| 568 | assert_se(send_one_fd_iov(pair[1], tmpfd, &iov, 1, MSG_DONTWAIT) > 0)do { if ((__builtin_expect(!!(!(send_one_fd_iov_sa(pair[1], tmpfd , &iov, 1, ((void*)0), 0, MSG_DONTWAIT) > 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("send_one_fd_iov(pair[1], tmpfd, &iov, 1, MSG_DONTWAIT) > 0" ), "../src/test/test-socket-util.c", 568, __PRETTY_FUNCTION__ ); } while (0); |
| 569 | _exit(EXIT_SUCCESS0); |
| 570 | } |
| 571 | |
| 572 | /* Parent */ |
| 573 | char buf[64]; |
| 574 | struct iovec iov = IOVEC_INIT(buf, sizeof(buf)-1){ .iov_base = (buf), .iov_len = (sizeof(buf)-1) }; |
| 575 | _cleanup_close___attribute__((cleanup(closep))) int fd = -1; |
| 576 | ssize_t k; |
| 577 | |
| 578 | pair[1] = safe_close(pair[1]); |
| 579 | |
| 580 | k = receive_one_fd_iov(pair[0], &iov, 1, MSG_DONTWAITMSG_DONTWAIT, &fd); |
| 581 | assert_se(k > 0)do { if ((__builtin_expect(!!(!(k > 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("k > 0"), "../src/test/test-socket-util.c" , 581, __PRETTY_FUNCTION__); } while (0); |
| 582 | buf[k] = 0; |
| 583 | assert_se(streq(buf, wire_contents))do { if ((__builtin_expect(!!(!((strcmp((buf),(wire_contents) ) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(buf, wire_contents)" ), "../src/test/test-socket-util.c", 583, __PRETTY_FUNCTION__ ); } while (0); |
| 584 | |
| 585 | assert_se(fd >= 0)do { if ((__builtin_expect(!!(!(fd >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("fd >= 0"), "../src/test/test-socket-util.c" , 585, __PRETTY_FUNCTION__); } while (0); |
| 586 | r = read(fd, buf, sizeof(buf)-1); |
| 587 | assert_se(r >= 0)do { if ((__builtin_expect(!!(!(r >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r >= 0"), "../src/test/test-socket-util.c" , 587, __PRETTY_FUNCTION__); } while (0); |
| 588 | buf[r] = 0; |
| 589 | assert_se(streq(buf, file_contents))do { if ((__builtin_expect(!!(!((strcmp((buf),(file_contents) ) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(buf, file_contents)" ), "../src/test/test-socket-util.c", 589, __PRETTY_FUNCTION__ ); } while (0); |
| 590 | } |
| 591 | |
| 592 | static void test_receive_nopassfd(void) { |
| 593 | _cleanup_close_pair___attribute__((cleanup(close_pairp))) int pair[2] = { -1, -1 }; |
| 594 | static const char wire_contents[] = "no fd passed here"; |
| 595 | int r; |
| 596 | |
| 597 | assert_se(socketpair(AF_UNIX, SOCK_DGRAM, 0, pair) >= 0)do { if ((__builtin_expect(!!(!(socketpair(1, SOCK_DGRAM, 0, pair ) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ( "socketpair(AF_UNIX, SOCK_DGRAM, 0, pair) >= 0"), "../src/test/test-socket-util.c" , 597, __PRETTY_FUNCTION__); } while (0); |
| 598 | |
| 599 | r = safe_fork("(receive_nopassfd)", FORK_DEATHSIG|FORK_LOG|FORK_WAIT, NULL((void*)0)); |
| 600 | assert_se(r >= 0)do { if ((__builtin_expect(!!(!(r >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r >= 0"), "../src/test/test-socket-util.c" , 600, __PRETTY_FUNCTION__); } while (0); |
| 601 | |
| 602 | if (r == 0) { |
| 603 | /* Child */ |
| 604 | struct iovec iov = IOVEC_INIT_STRING(wire_contents){ .iov_base = ((char*) wire_contents), .iov_len = (strlen(wire_contents )) }; |
| 605 | |
| 606 | pair[0] = safe_close(pair[0]); |
| 607 | |
| 608 | assert_se(send_one_fd_iov(pair[1], -1, &iov, 1, MSG_DONTWAIT) > 0)do { if ((__builtin_expect(!!(!(send_one_fd_iov_sa(pair[1], - 1, &iov, 1, ((void*)0), 0, MSG_DONTWAIT) > 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("send_one_fd_iov(pair[1], -1, &iov, 1, MSG_DONTWAIT) > 0" ), "../src/test/test-socket-util.c", 608, __PRETTY_FUNCTION__ ); } while (0); |
| 609 | _exit(EXIT_SUCCESS0); |
| 610 | } |
| 611 | |
| 612 | /* Parent */ |
| 613 | char buf[64]; |
| 614 | struct iovec iov = IOVEC_INIT(buf, sizeof(buf)-1){ .iov_base = (buf), .iov_len = (sizeof(buf)-1) }; |
| 615 | int fd = -999; |
| 616 | ssize_t k; |
| 617 | |
| 618 | pair[1] = safe_close(pair[1]); |
| 619 | |
| 620 | k = receive_one_fd_iov(pair[0], &iov, 1, MSG_DONTWAITMSG_DONTWAIT, &fd); |
| 621 | assert_se(k > 0)do { if ((__builtin_expect(!!(!(k > 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("k > 0"), "../src/test/test-socket-util.c" , 621, __PRETTY_FUNCTION__); } while (0); |
| 622 | buf[k] = 0; |
| 623 | assert_se(streq(buf, wire_contents))do { if ((__builtin_expect(!!(!((strcmp((buf),(wire_contents) ) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(buf, wire_contents)" ), "../src/test/test-socket-util.c", 623, __PRETTY_FUNCTION__ ); } while (0); |
| 624 | |
| 625 | /* no fd passed here, confirm it was reset */ |
| 626 | assert_se(fd == -1)do { if ((__builtin_expect(!!(!(fd == -1)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("fd == -1"), "../src/test/test-socket-util.c" , 626, __PRETTY_FUNCTION__); } while (0); |
| 627 | } |
| 628 | |
| 629 | static void test_send_nodata_nofd(void) { |
| 630 | _cleanup_close_pair___attribute__((cleanup(close_pairp))) int pair[2] = { -1, -1 }; |
| 631 | int r; |
| 632 | |
| 633 | assert_se(socketpair(AF_UNIX, SOCK_DGRAM, 0, pair) >= 0)do { if ((__builtin_expect(!!(!(socketpair(1, SOCK_DGRAM, 0, pair ) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ( "socketpair(AF_UNIX, SOCK_DGRAM, 0, pair) >= 0"), "../src/test/test-socket-util.c" , 633, __PRETTY_FUNCTION__); } while (0); |
| 634 | |
| 635 | r = safe_fork("(send_nodata_nofd)", FORK_DEATHSIG|FORK_LOG|FORK_WAIT, NULL((void*)0)); |
| 636 | assert_se(r >= 0)do { if ((__builtin_expect(!!(!(r >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r >= 0"), "../src/test/test-socket-util.c" , 636, __PRETTY_FUNCTION__); } while (0); |
| 637 | |
| 638 | if (r == 0) { |
| 639 | /* Child */ |
| 640 | pair[0] = safe_close(pair[0]); |
| 641 | |
| 642 | assert_se(send_one_fd_iov(pair[1], -1, NULL, 0, MSG_DONTWAIT) == -EINVAL)do { if ((__builtin_expect(!!(!(send_one_fd_iov_sa(pair[1], - 1, ((void*)0), 0, ((void*)0), 0, MSG_DONTWAIT) == -22)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("send_one_fd_iov(pair[1], -1, NULL, 0, MSG_DONTWAIT) == -EINVAL" ), "../src/test/test-socket-util.c", 642, __PRETTY_FUNCTION__ ); } while (0); |
| 643 | _exit(EXIT_SUCCESS0); |
| 644 | } |
| 645 | |
| 646 | /* Parent */ |
| 647 | char buf[64]; |
| 648 | struct iovec iov = IOVEC_INIT(buf, sizeof(buf)-1){ .iov_base = (buf), .iov_len = (sizeof(buf)-1) }; |
| 649 | int fd = -999; |
| 650 | ssize_t k; |
| 651 | |
| 652 | pair[1] = safe_close(pair[1]); |
| 653 | |
| 654 | k = receive_one_fd_iov(pair[0], &iov, 1, MSG_DONTWAITMSG_DONTWAIT, &fd); |
| 655 | /* recvmsg() will return errno EAGAIN if nothing was sent */ |
| 656 | assert_se(k == -EAGAIN)do { if ((__builtin_expect(!!(!(k == -11)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("k == -EAGAIN"), "../src/test/test-socket-util.c" , 656, __PRETTY_FUNCTION__); } while (0); |
| 657 | |
| 658 | /* receive_one_fd_iov returned error, so confirm &fd wasn't touched */ |
| 659 | assert_se(fd == -999)do { if ((__builtin_expect(!!(!(fd == -999)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("fd == -999"), "../src/test/test-socket-util.c" , 659, __PRETTY_FUNCTION__); } while (0); |
| 660 | } |
| 661 | |
| 662 | static void test_send_emptydata(void) { |
| 663 | _cleanup_close_pair___attribute__((cleanup(close_pairp))) int pair[2] = { -1, -1 }; |
| 664 | int r; |
| 665 | |
| 666 | assert_se(socketpair(AF_UNIX, SOCK_DGRAM, 0, pair) >= 0)do { if ((__builtin_expect(!!(!(socketpair(1, SOCK_DGRAM, 0, pair ) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ( "socketpair(AF_UNIX, SOCK_DGRAM, 0, pair) >= 0"), "../src/test/test-socket-util.c" , 666, __PRETTY_FUNCTION__); } while (0); |
| 667 | |
| 668 | r = safe_fork("(send_emptydata)", FORK_DEATHSIG|FORK_LOG|FORK_WAIT, NULL((void*)0)); |
| 669 | assert_se(r >= 0)do { if ((__builtin_expect(!!(!(r >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r >= 0"), "../src/test/test-socket-util.c" , 669, __PRETTY_FUNCTION__); } while (0); |
| 670 | |
| 671 | if (r == 0) { |
| 672 | /* Child */ |
| 673 | struct iovec iov = IOVEC_INIT_STRING(""){ .iov_base = ((char*) ""), .iov_len = (strlen("")) }; /* zero-length iov */ |
| 674 | assert_se(iov.iov_len == 0)do { if ((__builtin_expect(!!(!(iov.iov_len == 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("iov.iov_len == 0"), "../src/test/test-socket-util.c" , 674, __PRETTY_FUNCTION__); } while (0); |
| 675 | |
| 676 | pair[0] = safe_close(pair[0]); |
| 677 | |
| 678 | /* This will succeed, since iov is set. */ |
| 679 | assert_se(send_one_fd_iov(pair[1], -1, &iov, 1, MSG_DONTWAIT) == 0)do { if ((__builtin_expect(!!(!(send_one_fd_iov_sa(pair[1], - 1, &iov, 1, ((void*)0), 0, MSG_DONTWAIT) == 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("send_one_fd_iov(pair[1], -1, &iov, 1, MSG_DONTWAIT) == 0" ), "../src/test/test-socket-util.c", 679, __PRETTY_FUNCTION__ ); } while (0); |
| 680 | _exit(EXIT_SUCCESS0); |
| 681 | } |
| 682 | |
| 683 | /* Parent */ |
| 684 | char buf[64]; |
| 685 | struct iovec iov = IOVEC_INIT(buf, sizeof(buf)-1){ .iov_base = (buf), .iov_len = (sizeof(buf)-1) }; |
| 686 | int fd = -999; |
| 687 | ssize_t k; |
| 688 | |
| 689 | pair[1] = safe_close(pair[1]); |
| 690 | |
| 691 | k = receive_one_fd_iov(pair[0], &iov, 1, MSG_DONTWAITMSG_DONTWAIT, &fd); |
| 692 | /* receive_one_fd_iov() returns -EIO if an fd is not found and no data was returned. */ |
| 693 | assert_se(k == -EIO)do { if ((__builtin_expect(!!(!(k == -5)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("k == -EIO"), "../src/test/test-socket-util.c" , 693, __PRETTY_FUNCTION__); } while (0); |
| 694 | |
| 695 | /* receive_one_fd_iov returned error, so confirm &fd wasn't touched */ |
| 696 | assert_se(fd == -999)do { if ((__builtin_expect(!!(!(fd == -999)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("fd == -999"), "../src/test/test-socket-util.c" , 696, __PRETTY_FUNCTION__); } while (0); |
| 697 | } |
| 698 | |
| 699 | int main(int argc, char *argv[]) { |
| 700 | |
| 701 | log_set_max_level(LOG_DEBUG)log_set_max_level_realm(LOG_REALM_SYSTEMD, (7)); |
| 702 | |
| 703 | test_ifname_valid(); |
| 704 | |
| 705 | test_socket_address_parse(); |
| 706 | test_socket_address_parse_netlink(); |
| 707 | test_socket_address_equal(); |
| 708 | test_socket_address_get_path(); |
| 709 | test_socket_address_is(); |
| 710 | test_socket_address_is_netlink(); |
| 711 | |
| 712 | test_in_addr_is_null(); |
| 713 | test_in_addr_prefix_intersect(); |
| 714 | test_in_addr_prefix_next(); |
| 715 | test_in_addr_to_string(); |
| 716 | test_in_addr_ifindex_to_string(); |
| 717 | test_in_addr_ifindex_from_string_auto(); |
| 718 | |
| 719 | test_sockaddr_equal(); |
| 720 | |
| 721 | test_sockaddr_un_len(); |
| 722 | |
| 723 | test_in_addr_is_multicast(); |
| 724 | |
| 725 | test_getpeercred_getpeergroups(); |
| 726 | |
| 727 | test_passfd_read(); |
| 728 | test_passfd_contents_read(); |
| 729 | test_receive_nopassfd(); |
| 730 | test_send_nodata_nofd(); |
| 731 | test_send_emptydata(); |
| 732 | |
| 733 | return 0; |
| 734 | } |