diff mbox

'nolog' and 'debug' options cause "$-" to wreak havoc

Message ID 20708080-c91c-4f02-3198-bfcc6963ebe9@inlv.org (mailing list archive)
State Accepted
Delegated to: Herbert Xu
Headers show

Commit Message

Martijn Dekker March 6, 2018, 5:40 p.m. UTC
Op 29-03-17 om 20:02 schreef Martijn Dekker:
> Bug: if either the 'nolog' or the 'debug' option is set, trying to
> expand "$-" silently aborts parsing of an entire argument.
> 
> $ dash -o nolog -c 'set -fuC; echo "|$- are the options|"; \
> 	set +o nolog; echo "|$- are the options|"'
> |
> |uCf are the options|
> $ dash -o debug -c 'set -fuC; echo "|$- are the options|"; \
> 	set +o debug; echo "|$- are the options|"'
> |
> |uCf are the options|

This turned out to be easy to fix. The routine producing the "$-"
expansion failed to skip options for which there is no option letter,
but only a long-form name. In dash, 'nolog' and 'debug' are currently
the only two such options. Patch below.

- Martijn


--
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Herbert Xu March 10, 2018, 8:04 a.m. UTC | #1
On Tue, Mar 06, 2018 at 05:40:37PM +0000, Martijn Dekker wrote:
> Op 29-03-17 om 20:02 schreef Martijn Dekker:
> > Bug: if either the 'nolog' or the 'debug' option is set, trying to
> > expand "$-" silently aborts parsing of an entire argument.
> > 
> > $ dash -o nolog -c 'set -fuC; echo "|$- are the options|"; \
> > 	set +o nolog; echo "|$- are the options|"'
> > |
> > |uCf are the options|
> > $ dash -o debug -c 'set -fuC; echo "|$- are the options|"; \
> > 	set +o debug; echo "|$- are the options|"'
> > |
> > |uCf are the options|
> 
> This turned out to be easy to fix. The routine producing the "$-"
> expansion failed to skip options for which there is no option letter,
> but only a long-form name. In dash, 'nolog' and 'debug' are currently
> the only two such options. Patch below.

Patch applied.  Thanks.
diff mbox

Patch

diff --git a/src/expand.c b/src/expand.c
index 2a50830..71a0031 100644
--- a/src/expand.c
+++ b/src/expand.c
@@ -925,7 +925,7 @@  numvar:
 	case '-':
 		p = makestrspace(NOPTS, expdest);
 		for (i = NOPTS - 1; i >= 0; i--) {
-			if (optlist[i]) {
+			if (optlist[i] && optletters[i]) {
 				USTPUTC(optletters[i], p);
 				len++;
 			}