]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test-firewall-util: add more asserts on allocated variables
authorLuca Boccassi <luca.boccassi@microsoft.com>
Thu, 25 Mar 2021 10:49:06 +0000 (10:49 +0000)
committerLuca Boccassi <luca.boccassi@microsoft.com>
Thu, 25 Mar 2021 10:49:06 +0000 (10:49 +0000)
Makes things nicer for readers, and hopefully gives static analyzers
a hint on the origin/cleanup of the ctx pointer.
Coverity CID #1451399

src/test/test-firewall-util.c

index abc28d500d5712f6f4790f68dbe1a47ddf3b2b84..dfde01a678899a4fc3b22a68afb0c51cce5df99a 100644 (file)
@@ -14,6 +14,8 @@ static void test_v6(FirewallContext *ctx) {
         uint8_t prefixlen;
         int r;
 
+        assert_se(ctx);
+
         log_info("/* %s(backend=%s) */", __func__, firewall_backend_to_string(ctx->backend));
 
         if (!socket_ipv6_is_supported())
@@ -46,6 +48,7 @@ static void test_v6(FirewallContext *ctx) {
 
 static union in_addr_union *parse_addr(const char *str, union in_addr_union *u) {
         assert(str);
+        assert(u);
         assert_se(in_addr_from_string(AF_INET, str, u) >= 0);
         return u;
 }
@@ -54,6 +57,8 @@ static bool test_v4(FirewallContext *ctx) {
         union in_addr_union u, v;
         int r;
 
+        assert_se(ctx);
+
         log_info("/* %s(backend=%s) */", __func__, firewall_backend_to_string(ctx->backend));
 
         assert_se(fw_add_masquerade(&ctx, true, AF_INET, NULL, 0) == -EINVAL);
@@ -92,6 +97,7 @@ int main(int argc, char *argv[]) {
                 return log_tests_skipped("not root");
 
         assert_se(fw_ctx_new(&ctx) >= 0);
+        assert_se(ctx);
 
         if (ctx->backend == FW_BACKEND_NONE)
                 return EXIT_TEST_SKIP;