Found the same issue during testing of the autoconf script from smartmontools with various shells. With posh, the script returned a few bogus results.

The problem occurs when a quote string precedes the wildcard. The wildcard is also interpreted as quoted then:

$ posh -c 'case "foo" in "fo"*) echo OK;; *) echo FAIL; esac'
FAIL

$ posh -c 'case "fo*" in "fo"*) echo OK;; *) echo FAIL; esac'
OK

$ posh -c 'case "foo" in *"oo") echo OK;; *) echo FAIL; esac'
OK

$ posh -c 'case "foo" in fo*) echo OK;; *) echo FAIL; esac'
OK

Examining the source, I found

      case CQUOTE:
         quote = st->quote;    /* XXX correct? */
         continue;

Actually this isn't correct, because st->quote may refer to st_head.quote which is not initialized. The attached patch fixes the issue for the above cases. It may be necessary to also init other fields of std_head. There may also be a nesting problem with the 'st' chain.

Regards,
Christian

2014-07-07  Christian Franke  <fra...@computer.org>

	* eval.c (expand): Fix missing initialization of st_head.quote.
	(Closes #636601 ?)

diff -rup posh-0.12.3.orig/eval.c posh-0.12.3/eval.c
--- posh-0.12.3.orig/eval.c	2012-11-01 15:33:25.000000000 +0100
+++ posh-0.12.3/eval.c	2014-07-07 21:16:41.012243600 +0200
@@ -201,6 +201,7 @@ expand(const char *cp,	/* input word */
 	make_magic = 0;
 	word = (f&DOBLANK) ? IFS_WS : IFS_WORD;
 	st_head.next = NULL;
+	st_head.quote = 0;
 	st = &st_head;
 
 	while (1) {

Reply via email to