diff options
author | Ron Yorston <rmy@pobox.com> | 2015-09-04 10:32:41 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2015-09-04 22:23:54 +0200 |
commit | ca25af9b06b0c3ded77ac70087227896b34003c4 (patch) | |
tree | 6fd2f8a870814464e1b76e8c2573a8bd303acd20 | |
parent | b5be13ccd9ce2120468a381a5475955013c0f049 (diff) | |
download | busybox-w32-ca25af9b06b0c3ded77ac70087227896b34003c4.tar.gz busybox-w32-ca25af9b06b0c3ded77ac70087227896b34003c4.tar.bz2 busybox-w32-ca25af9b06b0c3ded77ac70087227896b34003c4.zip |
ash: fix slash treatment in expmeta
Commit 549deab caused this sequence of commands:
mkdir foo
cd foo
touch a b
echo "./"*
to return './*' instead of the expected './a ./b'. The problem
was caused by the backport of commit 880d952 from dash. In dash
the issue was fixed by two further commits by Herbert Xu:
<d6d06ff> [EXPAND] Fixed non-leading slash treatment in expmeta
<36f0fa8> [EXPAND] Fix slash treatment in expmeta
(See git://git.kernel.org/pub/scm/utils/dash/dash.git)
Apply these fixes to BusyBox ash, thus causing the new test
glob3.tests to succeed.
function old new delta
expmeta 469 528 +59
Reported-by: Aaro Koskinen <aaro.koskinen@iki.fi>
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | shell/ash.c | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/shell/ash.c b/shell/ash.c index f6190c3e2..42c91257e 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -6992,10 +6992,11 @@ expmeta(char *expdir, char *enddir, char *name) | |||
6992 | struct dirent *dp; | 6992 | struct dirent *dp; |
6993 | int atend; | 6993 | int atend; |
6994 | int matchdot; | 6994 | int matchdot; |
6995 | int esc; | ||
6995 | 6996 | ||
6996 | metaflag = 0; | 6997 | metaflag = 0; |
6997 | start = name; | 6998 | start = name; |
6998 | for (p = name; *p; p++) { | 6999 | for (p = name; esc = 0, *p; p += esc + 1) { |
6999 | if (*p == '*' || *p == '?') | 7000 | if (*p == '*' || *p == '?') |
7000 | metaflag = 1; | 7001 | metaflag = 1; |
7001 | else if (*p == '[') { | 7002 | else if (*p == '[') { |
@@ -7012,15 +7013,16 @@ expmeta(char *expdir, char *enddir, char *name) | |||
7012 | break; | 7013 | break; |
7013 | } | 7014 | } |
7014 | } | 7015 | } |
7015 | } else if (*p == '\\') | 7016 | } else { |
7016 | p++; | 7017 | if (*p == '\\') |
7017 | else if (*p == '/') { | 7018 | esc++; |
7018 | if (metaflag) | 7019 | if (p[esc] == '/') { |
7019 | goto out; | 7020 | if (metaflag) |
7020 | start = p + 1; | 7021 | break; |
7022 | start = p + esc + 1; | ||
7023 | } | ||
7021 | } | 7024 | } |
7022 | } | 7025 | } |
7023 | out: | ||
7024 | if (metaflag == 0) { /* we've reached the end of the file name */ | 7026 | if (metaflag == 0) { /* we've reached the end of the file name */ |
7025 | if (enddir != expdir) | 7027 | if (enddir != expdir) |
7026 | metaflag++; | 7028 | metaflag++; |
@@ -7060,7 +7062,8 @@ expmeta(char *expdir, char *enddir, char *name) | |||
7060 | atend = 1; | 7062 | atend = 1; |
7061 | } else { | 7063 | } else { |
7062 | atend = 0; | 7064 | atend = 0; |
7063 | *endname++ = '\0'; | 7065 | *endname = '\0'; |
7066 | endname += esc + 1; | ||
7064 | } | 7067 | } |
7065 | matchdot = 0; | 7068 | matchdot = 0; |
7066 | p = start; | 7069 | p = start; |
@@ -7085,7 +7088,7 @@ expmeta(char *expdir, char *enddir, char *name) | |||
7085 | } | 7088 | } |
7086 | closedir(dirp); | 7089 | closedir(dirp); |
7087 | if (!atend) | 7090 | if (!atend) |
7088 | endname[-1] = '/'; | 7091 | endname[-esc - 1] = esc ? '\\' : '/'; |
7089 | } | 7092 | } |
7090 | 7093 | ||
7091 | static struct strlist * | 7094 | static struct strlist * |