FreeBSD Bugzilla – Attachment 184754 Details for
Bug 220587
/bin/sh Incorrect options handling
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Fix option processing for sh -c and add tests
fix-sh.patch (text/plain), 3.50 KB, created by
Ryan Moeller
on 2017-07-27 04:27:08 UTC
(
hide
)
Description:
Fix option processing for sh -c and add tests
Filename:
MIME Type:
Creator:
Ryan Moeller
Created:
2017-07-27 04:27:08 UTC
Size:
3.50 KB
patch
obsolete
>diff --git a/bin/sh/options.c b/bin/sh/options.c >index d580436c134..f4ee337931b 100644 >--- a/bin/sh/options.c >+++ b/bin/sh/options.c >@@ -41,6 +41,7 @@ __FBSDID("$FreeBSD$"); > #include <signal.h> > #include <unistd.h> > #include <stdlib.h> >+#include <stdbool.h> > > #include "shell.h" > #define DEFINE_OPTIONS >@@ -148,10 +149,13 @@ optschanged(void) > static void > options(int cmdline) > { >+ bool saw_minus_c; > char *kp, *p; > int val; > int c; > >+ saw_minus_c = false; >+ > if (cmdline) > minusc = NULL; > while ((p = *argptr) != NULL) { >@@ -186,16 +190,13 @@ options(int cmdline) > val = 0; > } else { > argptr--; >+ if (saw_minus_c) >+ minusc = *argptr++; > break; > } > while ((c = *p++) != '\0') { > if (c == 'c' && cmdline) { >- char *q; >- >- q = *argptr++; >- if (q == NULL || minusc != NULL) >- error("Bad -c option"); >- minusc = q; >+ saw_minus_c = true; > } else if (c == 'o') { > minus_o(*argptr, val); > if (*argptr) >diff --git a/bin/sh/tests/Makefile b/bin/sh/tests/Makefile >index d93e19aea7e..75474c9e34c 100644 >--- a/bin/sh/tests/Makefile >+++ b/bin/sh/tests/Makefile >@@ -6,6 +6,7 @@ TESTS_SUBDIRS+= builtins > TESTS_SUBDIRS+= errors > TESTS_SUBDIRS+= execution > TESTS_SUBDIRS+= expansion >+TESTS_SUBDIRS+= options > TESTS_SUBDIRS+= parameters > TESTS_SUBDIRS+= parser > TESTS_SUBDIRS+= set-e >diff --git a/bin/sh/tests/options/Makefile b/bin/sh/tests/options/Makefile >new file mode 100644 >index 00000000000..43976d3e609 >--- /dev/null >+++ b/bin/sh/tests/options/Makefile >@@ -0,0 +1,16 @@ >+# $FreeBSD$ >+ >+PACKAGE= tests >+ >+TESTSDIR= ${TESTSBASE}/bin/sh/${.CURDIR:T} >+ >+.PATH: ${.CURDIR:H} >+ATF_TESTS_SH= functional_test >+ >+${PACKAGE}FILES+= sh-ac1.0 >+${PACKAGE}FILES+= sh-c1.0 >+${PACKAGE}FILES+= sh-ca1.0 >+${PACKAGE}FILES+= sh-m-c-a1.0 >+${PACKAGE}FILES+= sh-mca1.0 >+ >+.include <bsd.test.mk> >diff --git a/bin/sh/tests/options/sh-ac1.0 b/bin/sh/tests/options/sh-ac1.0 >new file mode 100644 >index 00000000000..b0269d5a956 >--- /dev/null >+++ b/bin/sh/tests/options/sh-ac1.0 >@@ -0,0 +1,5 @@ >+# $FreeBSD$ >+# Test that option processing ends after command_string and >+# processes options before c >+ >+${SH} -ac 'echo $-:$0' -m | grep -qx "a:-m" >diff --git a/bin/sh/tests/options/sh-c1.0 b/bin/sh/tests/options/sh-c1.0 >new file mode 100644 >index 00000000000..950c3a7b636 >--- /dev/null >+++ b/bin/sh/tests/options/sh-c1.0 >@@ -0,0 +1,4 @@ >+# $FreeBSD$ >+# Test that option processing ends after command_string >+ >+${SH} -c 'echo $0 $@' -m foo | grep -qx -- "-m foo" >diff --git a/bin/sh/tests/options/sh-ca1.0 b/bin/sh/tests/options/sh-ca1.0 >new file mode 100644 >index 00000000000..697bab63709 >--- /dev/null >+++ b/bin/sh/tests/options/sh-ca1.0 >@@ -0,0 +1,5 @@ >+# $FreeBSD$ >+# Test that option processing ends after command_string and processes >+# options after c >+ >+${SH} -ca 'echo $-:$0' -m | grep -qx "a:-m" >diff --git a/bin/sh/tests/options/sh-m-c-a1.0 b/bin/sh/tests/options/sh-m-c-a1.0 >new file mode 100644 >index 00000000000..034ea1d80eb >--- /dev/null >+++ b/bin/sh/tests/options/sh-m-c-a1.0 >@@ -0,0 +1,5 @@ >+# $FreeBSD$ >+# Test that option processing ends after command_string and processes >+# options before and after c >+ >+${SH} -m -c -a 'echo $-:$0:$@' -foo -bar | grep -qx "ma:-foo:-bar" >diff --git a/bin/sh/tests/options/sh-mca1.0 b/bin/sh/tests/options/sh-mca1.0 >new file mode 100644 >index 00000000000..7504ea6a791 >--- /dev/null >+++ b/bin/sh/tests/options/sh-mca1.0 >@@ -0,0 +1,5 @@ >+# $FreeBSD$ >+# Test that option processing ends after command_string and processes >+# flags before and after c >+ >+${SH} -mca 'echo $-:$0:$@' -foo -bar | grep -qx "ma:-foo:-bar"
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 220587
:
184215
|
184754
|
185108
|
185110
|
185396
|
185397