diff -ur dash-0.5.9.1.orig/src/mystring.c dash-0.5.9.1/src/mystring.c --- dash-0.5.9.1.orig/src/mystring.c 2017-02-28 00:14:47.000000000 +0100 +++ dash-0.5.9.1/src/mystring.c 2017-02-28 00:10:40.000000000 +0100 @@ -55,6 +55,7 @@ #include "memalloc.h" #include "parser.h" #include "system.h" +#include "token_vars.h" char nullstr[1]; /* zero length string */ @@ -181,11 +182,29 @@ return 1; } +/* + * Check if a string is identical to a shell keyword (reserved word). + */ + +int +is_kwd(const char *s) +{ + int i = 0; + + do { + if (strcmp(s, parsekwd[i++]) == 0) + return 1; + } while (*parsekwd[i-1] != '}'); /* assuming that "}" is last entry */ + + return 0; +} + /* * Produce a possibly single quoted string suitable as input to the shell. * If 'conditional' is nonzero, quoting is only done if the string contains - * non-shellsafe characters; if it is zero, quoting is always done. + * non-shellsafe characters, or is identical to a shell keyword (reserved + * word); if it is zero, quoting is always done. * If quoting was done, the return string is allocated on the stack, * otherwise a pointer to the original string is returned. */ @@ -194,7 +213,7 @@ single_quote(const char *s, int conditional) { char *p; - if (conditional && s[strspn(s, SHELLSAFECHARS)] == '\0') + if (conditional && s[strspn(s, SHELLSAFECHARS)] == '\0' && ! is_kwd(s)) return (char *)s; STARTSTACKSTR(p); diff -ur dash-0.5.9.1.orig/src/mystring.h dash-0.5.9.1/src/mystring.h --- dash-0.5.9.1.orig/src/mystring.h 2017-02-28 00:14:47.000000000 +0100 +++ dash-0.5.9.1/src/mystring.h 2017-02-28 00:10:40.000000000 +0100 @@ -63,4 +63,4 @@ #define scopy(s1, s2) ((void)strcpy(s2, s1)) /* Characters that don't need quoting before re-entry into the shell */ -#define SHELLSAFECHARS "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz%+,./:=@_^!-" +#define SHELLSAFECHARS "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz%+,./:@_^-"