[openssh-commits] [openssh] 01/01: upstream: test argv_split() optional termination on comments

git+noreply at mindrot.org git+noreply at mindrot.org
Tue Jun 8 17:42:02 AEST 2021


This is an automated email from the git hooks/post-receive script.

djm pushed a commit to branch master
in repository openssh.

commit 78e30af3e2b2dd540a341cc827c6b98dd8b0a6de
Author: djm at openbsd.org <djm at openbsd.org>
Date:   Tue Jun 8 07:40:12 2021 +0000

    upstream: test argv_split() optional termination on comments
    
    OpenBSD-Regress-ID: 9fd1c4a27a409897437c010cfd79c54b639a059c
---
 regress/unittests/misc/test_argv.c | 98 +++++++++++++++++++++++++++-----------
 1 file changed, 69 insertions(+), 29 deletions(-)

diff --git a/regress/unittests/misc/test_argv.c b/regress/unittests/misc/test_argv.c
index a422a201..d5c139a4 100644
--- a/regress/unittests/misc/test_argv.c
+++ b/regress/unittests/misc/test_argv.c
@@ -1,4 +1,4 @@
-/* 	$OpenBSD: test_argv.c,v 1.2 2021/05/21 04:03:47 djm Exp $ */
+/* 	$OpenBSD: test_argv.c,v 1.3 2021/06/08 07:40:12 djm Exp $ */
 /*
  * Regress test for misc argv handling functions.
  *
@@ -21,16 +21,6 @@
 
 void test_argv(void);
 
-static void
-free_argv(char **av, int ac)
-{
-	int i;
-
-	for (i = 0; i < ac; i++)
-		free(av[i]);
-	free(av);
-}
-
 void
 test_argv(void)
 {
@@ -39,19 +29,18 @@ test_argv(void)
 
 #define RESET_ARGV() \
 	do { \
-		free_argv(av, ac); \
+		argv_free(av, ac); \
 		av = NULL; \
 		ac = -1; \
 	} while (0)
 
 	TEST_START("empty args");
-	RESET_ARGV();
-	ASSERT_INT_EQ(argv_split("", &ac, &av), 0);
+	ASSERT_INT_EQ(argv_split("", &ac, &av, 0), 0);
 	ASSERT_INT_EQ(ac, 0);
 	ASSERT_PTR_NE(av, NULL);
 	ASSERT_PTR_EQ(av[0], NULL);
 	RESET_ARGV();
-	ASSERT_INT_EQ(argv_split("    ", &ac, &av), 0);
+	ASSERT_INT_EQ(argv_split("    ", &ac, &av, 0), 0);
 	ASSERT_INT_EQ(ac, 0);
 	ASSERT_PTR_NE(av, NULL);
 	ASSERT_PTR_EQ(av[0], NULL);
@@ -59,14 +48,13 @@ test_argv(void)
 	TEST_DONE();
 
 	TEST_START("trivial args");
-	RESET_ARGV();
-	ASSERT_INT_EQ(argv_split("leamas", &ac, &av), 0);
+	ASSERT_INT_EQ(argv_split("leamas", &ac, &av, 0), 0);
 	ASSERT_INT_EQ(ac, 1);
 	ASSERT_PTR_NE(av, NULL);
 	ASSERT_STRING_EQ(av[0], "leamas");
 	ASSERT_PTR_EQ(av[1], NULL);
 	RESET_ARGV();
-	ASSERT_INT_EQ(argv_split("smiley leamas", &ac, &av), 0);
+	ASSERT_INT_EQ(argv_split("smiley leamas", &ac, &av, 0), 0);
 	ASSERT_INT_EQ(ac, 2);
 	ASSERT_PTR_NE(av, NULL);
 	ASSERT_STRING_EQ(av[0], "smiley");
@@ -76,27 +64,26 @@ test_argv(void)
 	TEST_DONE();
 
 	TEST_START("quoted");
-	RESET_ARGV();
-	ASSERT_INT_EQ(argv_split("\"smiley\"", &ac, &av), 0);
+	ASSERT_INT_EQ(argv_split("\"smiley\"", &ac, &av, 0), 0);
 	ASSERT_INT_EQ(ac, 1);
 	ASSERT_PTR_NE(av, NULL);
 	ASSERT_STRING_EQ(av[0], "smiley");
 	ASSERT_PTR_EQ(av[1], NULL);
 	RESET_ARGV();
-	ASSERT_INT_EQ(argv_split("leamas \" smiley \"", &ac, &av), 0);
+	ASSERT_INT_EQ(argv_split("leamas \" smiley \"", &ac, &av, 0), 0);
 	ASSERT_INT_EQ(ac, 2);
 	ASSERT_PTR_NE(av, NULL);
 	ASSERT_STRING_EQ(av[0], "leamas");
 	ASSERT_STRING_EQ(av[1], " smiley ");
 	ASSERT_PTR_EQ(av[2], NULL);
 	RESET_ARGV();
-	ASSERT_INT_EQ(argv_split("\"smiley leamas\"", &ac, &av), 0);
+	ASSERT_INT_EQ(argv_split("\"smiley leamas\"", &ac, &av, 0), 0);
 	ASSERT_INT_EQ(ac, 1);
 	ASSERT_PTR_NE(av, NULL);
 	ASSERT_STRING_EQ(av[0], "smiley leamas");
 	ASSERT_PTR_EQ(av[1], NULL);
 	RESET_ARGV();
-	ASSERT_INT_EQ(argv_split("smiley\" leamas\" liz", &ac, &av), 0);
+	ASSERT_INT_EQ(argv_split("smiley\" leamas\" liz", &ac, &av, 0), 0);
 	ASSERT_INT_EQ(ac, 2);
 	ASSERT_PTR_NE(av, NULL);
 	ASSERT_STRING_EQ(av[0], "smiley leamas");
@@ -106,39 +93,92 @@ test_argv(void)
 	TEST_DONE();
 
 	TEST_START("escaped");
-	RESET_ARGV();
-	ASSERT_INT_EQ(argv_split("\\\"smiley\\'", &ac, &av), 0);
+	ASSERT_INT_EQ(argv_split("\\\"smiley\\'", &ac, &av, 0), 0);
 	ASSERT_INT_EQ(ac, 1);
 	ASSERT_PTR_NE(av, NULL);
 	ASSERT_STRING_EQ(av[0], "\"smiley'");
 	ASSERT_PTR_EQ(av[1], NULL);
 	RESET_ARGV();
-	ASSERT_INT_EQ(argv_split("'\\'smiley\\\"'", &ac, &av), 0);
+	ASSERT_INT_EQ(argv_split("'\\'smiley\\\"'", &ac, &av, 0), 0);
 	ASSERT_INT_EQ(ac, 1);
 	ASSERT_PTR_NE(av, NULL);
 	ASSERT_STRING_EQ(av[0], "'smiley\"");
 	ASSERT_PTR_EQ(av[1], NULL);
 	RESET_ARGV();
-	ASSERT_INT_EQ(argv_split("smiley\\'s leamas\\'", &ac, &av), 0);
+	ASSERT_INT_EQ(argv_split("smiley\\'s leamas\\'", &ac, &av, 0), 0);
 	ASSERT_INT_EQ(ac, 2);
 	ASSERT_PTR_NE(av, NULL);
 	ASSERT_STRING_EQ(av[0], "smiley's");
 	ASSERT_STRING_EQ(av[1], "leamas'");
 	ASSERT_PTR_EQ(av[2], NULL);
 	RESET_ARGV();
-	ASSERT_INT_EQ(argv_split("leamas\\\\smiley", &ac, &av), 0);
+	ASSERT_INT_EQ(argv_split("leamas\\\\smiley", &ac, &av, 0), 0);
 	ASSERT_INT_EQ(ac, 1);
 	ASSERT_PTR_NE(av, NULL);
 	ASSERT_STRING_EQ(av[0], "leamas\\smiley");
 	ASSERT_PTR_EQ(av[1], NULL);
 	RESET_ARGV();
-	ASSERT_INT_EQ(argv_split("leamas\\\\ \\\\smiley", &ac, &av), 0);
+	ASSERT_INT_EQ(argv_split("leamas\\\\ \\\\smiley", &ac, &av, 0), 0);
 	ASSERT_INT_EQ(ac, 2);
 	ASSERT_PTR_NE(av, NULL);
 	ASSERT_STRING_EQ(av[0], "leamas\\");
 	ASSERT_STRING_EQ(av[1], "\\smiley");
 	ASSERT_PTR_EQ(av[2], NULL);
 	RESET_ARGV();
+	ASSERT_INT_EQ(argv_split("smiley\\ leamas", &ac, &av, 0), 0);
+	ASSERT_INT_EQ(ac, 1);
+	ASSERT_PTR_NE(av, NULL);
+	ASSERT_STRING_EQ(av[0], "smiley leamas");
+	ASSERT_PTR_EQ(av[1], NULL);
+	RESET_ARGV();
+	TEST_DONE();
+
+	TEST_START("quoted escaped");
+	ASSERT_INT_EQ(argv_split("'smiley\\ leamas'", &ac, &av, 0), 0);
+	ASSERT_INT_EQ(ac, 1);
+	ASSERT_PTR_NE(av, NULL);
+	ASSERT_STRING_EQ(av[0], "smiley\\ leamas");
+	ASSERT_PTR_EQ(av[1], NULL);
+	RESET_ARGV();
+	ASSERT_INT_EQ(argv_split("\"smiley\\ leamas\"", &ac, &av, 0), 0);
+	ASSERT_INT_EQ(ac, 1);
+	ASSERT_PTR_NE(av, NULL);
+	ASSERT_STRING_EQ(av[0], "smiley\\ leamas");
+	ASSERT_PTR_EQ(av[1], NULL);
+	RESET_ARGV();
+	TEST_DONE();
+
+	TEST_START("comments");
+	ASSERT_INT_EQ(argv_split("# gold", &ac, &av, 0), 0);
+	ASSERT_INT_EQ(ac, 2);
+	ASSERT_PTR_NE(av, NULL);
+	ASSERT_STRING_EQ(av[0], "#");
+	ASSERT_STRING_EQ(av[1], "gold");
+	ASSERT_PTR_EQ(av[2], NULL);
+	RESET_ARGV();
+	ASSERT_INT_EQ(argv_split("# gold", &ac, &av, 1), 0);
+	ASSERT_INT_EQ(ac, 0);
+	ASSERT_PTR_NE(av, NULL);
+	ASSERT_PTR_EQ(av[0], NULL);
+	RESET_ARGV();
+	ASSERT_INT_EQ(argv_split("leamas#gold", &ac, &av, 1), 0);
+	ASSERT_INT_EQ(ac, 1);
+	ASSERT_PTR_NE(av, NULL);
+	ASSERT_STRING_EQ(av[0], "leamas#gold");
+	ASSERT_PTR_EQ(av[1], NULL);
+	RESET_ARGV();
+	ASSERT_INT_EQ(argv_split("\"leamas # gold\"", &ac, &av, 1), 0);
+	ASSERT_INT_EQ(ac, 1);
+	ASSERT_PTR_NE(av, NULL);
+	ASSERT_STRING_EQ(av[0], "leamas # gold");
+	ASSERT_PTR_EQ(av[1], NULL);
+	RESET_ARGV();
+	ASSERT_INT_EQ(argv_split("\"leamas\"#gold", &ac, &av, 1), 0);
+	ASSERT_INT_EQ(ac, 1);
+	ASSERT_PTR_NE(av, NULL);
+	ASSERT_STRING_EQ(av[0], "leamas#gold");
+	ASSERT_PTR_EQ(av[1], NULL);
+	RESET_ARGV();
 	TEST_DONE();
 
 	/* XXX test char *argv_assemble(int argc, char **argv) */

-- 
To stop receiving notification emails like this one, please contact
djm at mindrot.org.


More information about the openssh-commits mailing list