]> git.ipfire.org Git - thirdparty/openssh-portable.git/commitdiff
upstream: Set user, host and path to NULL immediately before calling
authordtucker@openbsd.org <dtucker@openbsd.org>
Thu, 12 Jun 2025 10:09:39 +0000 (10:09 +0000)
committerDarren Tucker <dtucker@dtucker.net>
Thu, 12 Jun 2025 10:39:30 +0000 (20:39 +1000)
parse_user_host_path in tests.  This ensures that we don't accidentally use
the previous value if the function under test doesn't set them Also fixes
Coverity CIDs 405056 405065 405066.

OpenBSD-Regress-ID: 43678ff59001712f32214fe303b1c21c163c2960

regress/unittests/misc/test_parse.c

index 1f1ea31d149c251fb436f2ac5920448961f88ebf..c66028aec5e6fd21e6a9ef3d0d27de57b8a1feab 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: test_parse.c,v 1.2 2021/12/14 21:25:27 deraadt Exp $ */
+/*     $OpenBSD: test_parse.c,v 1.3 2025/06/12 10:09:39 dtucker Exp $ */
 /*
  * Regress test for misc user/host/URI parsing functions.
  *
@@ -29,6 +29,7 @@ test_parse(void)
        char *user, *host, *path;
 
        TEST_START("misc_parse_user_host_path");
+       user = host = path = NULL;
        ASSERT_INT_EQ(parse_user_host_path("someuser@some.host:some/path",
            &user, &host, &path), 0);
        ASSERT_STRING_EQ(user, "someuser");
@@ -38,6 +39,7 @@ test_parse(void)
        TEST_DONE();
 
        TEST_START("misc_parse_user_ipv4_path");
+       user = host = path = NULL;
        ASSERT_INT_EQ(parse_user_host_path("someuser@1.22.33.144:some/path",
            &user, &host, &path), 0);
        ASSERT_STRING_EQ(user, "someuser");
@@ -47,6 +49,7 @@ test_parse(void)
        TEST_DONE();
 
        TEST_START("misc_parse_user_[ipv4]_path");
+       user = host = path = NULL;
        ASSERT_INT_EQ(parse_user_host_path("someuser@[1.22.33.144]:some/path",
            &user, &host, &path), 0);
        ASSERT_STRING_EQ(user, "someuser");
@@ -56,6 +59,7 @@ test_parse(void)
        TEST_DONE();
 
        TEST_START("misc_parse_user_[ipv4]_nopath");
+       user = host = path = NULL;
        ASSERT_INT_EQ(parse_user_host_path("someuser@[1.22.33.144]:",
            &user, &host, &path), 0);
        ASSERT_STRING_EQ(user, "someuser");
@@ -65,6 +69,7 @@ test_parse(void)
        TEST_DONE();
 
        TEST_START("misc_parse_user_ipv6_path");
+       user = host = path = NULL;
        ASSERT_INT_EQ(parse_user_host_path("someuser@[::1]:some/path",
            &user, &host, &path), 0);
        ASSERT_STRING_EQ(user, "someuser");
@@ -74,6 +79,7 @@ test_parse(void)
        TEST_DONE();
 
        TEST_START("misc_parse_uri");
+       user = host = path = NULL;
        ASSERT_INT_EQ(parse_uri("ssh", "ssh://someuser@some.host:22/some/path",
            &user, &host, &port, &path), 0);
        ASSERT_STRING_EQ(user, "someuser");