From 868506eb427c9dcc6d869cd4885679be04e1b7dd Mon Sep 17 00:00:00 2001 From: Joe Simmons-Talbott Date: Wed, 22 Mar 2023 14:04:30 -0400 Subject: system: Add "--" after "-c" for sh (BZ #28519) Prevent sh from interpreting a user string as shell options if it starts with '-' or '+'. Since the version of /bin/sh used for testing system() is different from the full-fledged system /bin/sh add support to it for handling "--" after "-c". Add a testcase to ensure the expected behavior. Signed-off-by: Joe Simmons-Talbott Reviewed-by: Adhemerval Zanella --- stdlib/tst-system.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'stdlib') diff --git a/stdlib/tst-system.c b/stdlib/tst-system.c index 47a0afe..3a55ec2 100644 --- a/stdlib/tst-system.c +++ b/stdlib/tst-system.c @@ -148,6 +148,20 @@ do_test (void) { struct support_capture_subprocess result; + const char *cmd = "-echo"; + result = support_capture_subprocess (call_system, + &(struct args) { cmd, 127 }); + support_capture_subprocess_check (&result, "system", 0, sc_allow_stderr | + sc_allow_stdout); + char *returnerr = xasprintf ("%s: execing -echo failed: " + "No such file or directory", + basename(_PATH_BSHELL)); + TEST_COMPARE_STRING (result.err.buffer, returnerr); + free (returnerr); + } + + { + struct support_capture_subprocess result; result = support_capture_subprocess (call_system, &(struct args) { "exit 1", 1 }); support_capture_subprocess_check (&result, "system", 0, sc_allow_none); -- cgit v1.1