summaryrefslogtreecommitdiff
path: root/test/testproc.c
diff options
context:
space:
mode:
authorIvan Zhakov <ivan@apache.org>2019-10-15 10:59:58 +0000
committerIvan Zhakov <ivan@apache.org>2019-10-15 10:59:58 +0000
commit51b539596a9676ccc9b392b5b35c7a60174b1844 (patch)
tree0e941ca85ba6e9986fffdc8a51daec6d1e5e1eac /test/testproc.c
parentcd40cc64f1d526f6c1659dd5777a36fd58031597 (diff)
downloadapr-51b539596a9676ccc9b392b5b35c7a60174b1844.tar.gz
apr_proc_create(): Properly escape arguments containing whitespace characters
on Windows. * CMakeLists.txt (single_source_programs): Add test/echoargs.c. * test/echoargs.c: New test app for test_proc_args test. * test/testproc.c (test_proc_args): New test. (testproc): Add test_proc_args to test list. * threadproc/win32/proc.c (quote_arg): New. Helper for apr_proc_create(). (apr_proc_create): Use quote_arg() helper to escape arguments in command line. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1868477 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'test/testproc.c')
-rw-r--r--test/testproc.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/test/testproc.c b/test/testproc.c
index c86fb2997..bf622fb65 100644
--- a/test/testproc.c
+++ b/test/testproc.c
@@ -160,6 +160,71 @@ static void test_file_redir(abts_case *tc, void *data)
ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
}
+static void test_proc_args(abts_case* tc, void* data)
+{
+ const char* args[10];
+ apr_procattr_t* attr;
+ apr_status_t rv;
+ char *progname;
+ const char *expected;
+ const char *actual;
+
+ apr_filepath_merge(&progname, NULL, "echoargs" EXTENSION, 0, p);
+
+ rv = apr_procattr_create(&attr, p);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+ rv = apr_procattr_io_set(attr, APR_NO_PIPE, APR_FULL_BLOCK, APR_NO_PIPE);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+ rv = apr_procattr_cmdtype_set(attr, APR_PROGRAM_ENV);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+ args[0] = progname;
+ args[1] = "1";
+ args[2] = "";
+ args[3] = "\"te st";
+ args[4] = " a\\b";
+ args[5] = " a\\\\b";
+ args[6] = " \\";
+ args[7] = "new\nline";
+ args[8] = " \\\\";
+ args[9] = NULL;
+
+ rv = apr_proc_create(&newproc, progname, args, NULL, attr, p);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+ actual = "";
+ while (1)
+ {
+ char buf[1024];
+ apr_size_t length = sizeof(buf);
+
+ rv = apr_file_read(newproc.out, buf, &length);
+ if (APR_STATUS_IS_EOF(rv)) {
+ break;
+ }
+ else if (rv != APR_SUCCESS)
+ {
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+ break;
+ }
+
+ buf[length] = 0;
+ actual = apr_pstrcat(p, actual, buf, NULL);
+ }
+
+ expected = "1" ","
+ "" ","
+ "\"te st" ","
+ " a\\b" ","
+ " a\\\\b" ","
+ " \\" ","
+ "new\nline" ","
+ " \\\\";
+ ABTS_STR_EQUAL(tc, expected, actual);
+}
+
abts_suite *testproc(abts_suite *suite)
{
suite = ADD_SUITE(suite)
@@ -168,6 +233,7 @@ abts_suite *testproc(abts_suite *suite)
abts_run_test(suite, test_create_proc, NULL);
abts_run_test(suite, test_proc_wait, NULL);
abts_run_test(suite, test_file_redir, NULL);
+ abts_run_test(suite, test_proc_args, NULL);
return suite;
}