This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: wordexp(3) -- A[0]='a b' gives error
- From: William Park <opengeometry at yahoo dot ca>
- To: libc-alpha at sourceware dot org
- Date: Fri, 18 Oct 2013 13:20:53 -0400
- Subject: Re: wordexp(3) -- A[0]='a b' gives error
- Authentication-results: sourceware.org; auth=none
- References: <20131017062214 dot GA29514 at node1 dot localdomain>
On Thu, Oct 17, 2013 at 02:22:14AM -0400, William Park wrote:
> Hi, I'm not sure if it's bug or just misunderstanding. Given two
> similar cases,
>
> wordexp ("one: A[0]='a b' end", &w, 0); --> error=5 (WRDE_SYNTAX)
> wordexp ("one: 'A[0]=a b' end", &w, 0); --> ok
>
> the result should be 3 strings,
>
> one:
> A[0]=a b
> end
>
> just like shell. Yet, I get error for the first case. I think
> wordexp() is getting confused about glob [0] which is followed by
> <single-quote> and then <space>.
Bug report has been submitted (Bug 16059). I was told to post my patch
to <libc-alpha> also. I'm subscribed to the list, so no need to CC me.
wordexp(3) stops on whitespace when scanning for glob pattern, even if
it occurs inside quoted string (single or double). So, this patch
suppresses splitting on whitespaces when inside quote for glob pattern.
PS. Perhaps we should add WRDE_NOGLOB flag to prevent globbing, just
like WRDE_NOCMD for command substitution.
--
William
diff -ru ../glibc-2.18--orig/ChangeLog ./ChangeLog
--- ../glibc-2.18--orig/ChangeLog 2013-08-10 18:52:55.000000000 -0400
+++ ./ChangeLog 2013-10-18 12:15:55.307041591 -0400
@@ -1,3 +1,7 @@
+2013-10-18 William Park <opengeometry@yahoo.ca>
+ * posix/wordexp.c (parse_glob): Don't split on whitespace inside
+ quoted string in glob pattern.
+
2013-08-03 David S. Miller <davem@davemloft.net>
* po/ko.po: Update Korean translation from translation project.
Only in ./posix: tags
diff -ru ../glibc-2.18--orig/posix/wordexp.c ./posix/wordexp.c
--- ../glibc-2.18--orig/posix/wordexp.c 2013-08-10 18:52:55.000000000 -0400
+++ ./posix/wordexp.c 2013-10-18 11:55:58.088288952 -0400
@@ -452,7 +452,7 @@
glob_list.we_offs = 0;
for (; words[*offset] != '\0'; ++*offset)
{
- if (strchr (ifs, words[*offset]) != NULL)
+ if (!quoted && strchr (ifs, words[*offset]) != NULL)
/* Reached IFS */
break;