]> git.ipfire.org Git - thirdparty/openssh-portable.git/commitdiff
upstream: memory leaks in unit tests
authordjm@openbsd.org <djm@openbsd.org>
Mon, 15 Sep 2025 03:00:22 +0000 (03:00 +0000)
committerDamien Miller <djm@mindrot.org>
Mon, 15 Sep 2025 06:13:34 +0000 (16:13 +1000)
OpenBSD-Regress-ID: af11ac7b8034b99ca324af4dae1ef5cd7700b273

regress/unittests/misc/test_expand.c
regress/unittests/sshbuf/test_sshbuf_getput_basic.c
regress/unittests/sshbuf/test_sshbuf_misc.c

index b72a1e9a84243257aa917272d6e9587cf6a2692a..a8be8d9f488ec2d6af112f06c4ccf2cf3d3e0d19 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: test_expand.c,v 1.3 2021/12/14 21:25:27 deraadt Exp $ */
+/*     $OpenBSD: test_expand.c,v 1.4 2025/09/15 03:00:22 djm Exp $ */
 /*
  * Regress test for misc string expansion functions.
  *
@@ -71,17 +71,26 @@ test_expand(void)
        TEST_DONE();
 
        TEST_START("percent_expand");
-       ASSERT_STRING_EQ(percent_expand("%%", "%h", "foo", NULL), "%");
-       ASSERT_STRING_EQ(percent_expand("%h", "h", "foo", NULL), "foo");
-       ASSERT_STRING_EQ(percent_expand("%h ", "h", "foo", NULL), "foo ");
-       ASSERT_STRING_EQ(percent_expand(" %h", "h", "foo", NULL), " foo");
-       ASSERT_STRING_EQ(percent_expand(" %h ", "h", "foo", NULL), " foo ");
-       ASSERT_STRING_EQ(percent_expand(" %a%b ", "a", "foo", "b", "bar", NULL),
-           " foobar ");
+#define CHECK_ONE(val, expect) \
+       ASSERT_STRING_EQ(val, expect); \
+       free(val);
+       ret = percent_expand("%%", "%h", "foo", NULL);
+       CHECK_ONE(ret, "%");
+       ret = percent_expand("%h", "h", "foo", NULL);
+       CHECK_ONE(ret, "foo");
+       ret = percent_expand("%h ", "h", "foo", NULL);
+       CHECK_ONE(ret, "foo ");
+       ret = percent_expand(" %h", "h", "foo", NULL);
+       CHECK_ONE(ret, " foo");
+       ret = percent_expand(" %h ", "h", "foo", NULL);
+       CHECK_ONE(ret, " foo ");
+       ret = percent_expand(" %a%b ", "a", "foo", "b", "bar", NULL);
+       CHECK_ONE(ret, " foobar ");
        TEST_DONE();
 
        TEST_START("percent_dollar_expand");
-       ASSERT_STRING_EQ(percent_dollar_expand("%h${FOO}", "h", "foo", NULL),
-           "foobar");
+       ret = percent_dollar_expand("%h${FOO}", "h", "foo", NULL);
+       CHECK_ONE(ret, "foobar");
+#undef CHECK_ONE
        TEST_DONE();
 }
index 058bf17d474b33d9d2f7c9559a1bfc4ee2d81379..bfe61a8773bc06b19d3a523ccf6e7b379a273054 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: test_sshbuf_getput_basic.c,v 1.4 2025/06/13 07:35:14 dtucker Exp $ */
+/*     $OpenBSD: test_sshbuf_getput_basic.c,v 1.5 2025/09/15 03:00:22 djm Exp $ */
 /*
  * Regress test for sshbuf.h buffer API
  *
@@ -609,6 +609,7 @@ sshbuf_getput_basic_tests(void)
        ASSERT_PTR_NE(s2, NULL);
        ASSERT_STRING_EQ(s2, "00000000000000000000");
        sshbuf_free(p1);
+       free(s2);
        TEST_DONE();
 
        TEST_START("sshbuf_poke_u16");
@@ -643,6 +644,7 @@ sshbuf_getput_basic_tests(void)
        ASSERT_PTR_NE(s2, NULL);
        ASSERT_STRING_EQ(s2, "00000000000000000000");
        sshbuf_free(p1);
+       free(s2);
        TEST_DONE();
 
        TEST_START("sshbuf_poke_u8");
@@ -673,6 +675,7 @@ sshbuf_getput_basic_tests(void)
        ASSERT_PTR_NE(s2, NULL);
        ASSERT_STRING_EQ(s2, "00000000000000000000");
        sshbuf_free(p1);
+       free(s2);
        TEST_DONE();
 
        TEST_START("sshbuf_poke");
@@ -707,5 +710,6 @@ sshbuf_getput_basic_tests(void)
        ASSERT_PTR_NE(s2, NULL);
        ASSERT_STRING_EQ(s2, "00000000000000000000");
        sshbuf_free(p1);
+       free(s2);
        TEST_DONE();
 }
index 58f55eee89ae33d611ff789fc89d4e12c510cde9..6b5b380d852422df9389f155f6071e93382ac6fb 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: test_sshbuf_misc.c,v 1.6 2025/09/04 00:37:10 djm Exp $ */
+/*     $OpenBSD: test_sshbuf_misc.c,v 1.7 2025/09/15 03:00:22 djm Exp $ */
 /*
  * Regress test for sshbuf.h buffer API
  *
@@ -214,6 +214,7 @@ test_sshbuf_cmp(void)
        ASSERT_INT_EQ(sshbuf_cmp(p1, 1000, "silence", 7),
            SSH_ERR_MESSAGE_INCOMPLETE);
        ASSERT_INT_EQ(sshbuf_cmp(p1, 0, msg, sizeof(msg) - 1), 0);
+       sshbuf_free(p1);
        TEST_DONE();
 }
 
@@ -252,6 +253,7 @@ test_sshbuf_find(void)
            SSH_ERR_MESSAGE_INCOMPLETE);
        ASSERT_INT_EQ(sshbuf_find(p1, 0, msg + 1, sizeof(msg) - 2, &sz), 0);
        ASSERT_SIZE_T_EQ(sz, 1);
+       sshbuf_free(p1);
        TEST_DONE();
 }