summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2008-05-19 09:15:05 +0800
committerHerbert Xu <herbert@gondor.apana.org.au>2008-05-19 09:15:05 +0800
commitd6d06ff5c2ea0fa44becc5ef4340e5f2f15073e4 (patch)
tree36bf908c575bbc5da9286a925bb1ce64eef54122 /src
parent[ARITH] Fixed lexical error on & and | (diff)
downloaddash-d6d06ff5c2ea0fa44becc5ef4340e5f2f15073e4.tar.gz
dash-d6d06ff5c2ea0fa44becc5ef4340e5f2f15073e4.zip
[EXPAND] Fixed non-leading slash treatment in expmeta
Back in January an attempt was made to fix the interpretation of
quoted slashes in expmeta.  However, this only fixed those cases
where the quoted slash is at the front of the word.  The case of
non-leading slashes caused the previous directory part to gain a
back slash suffix which causes subsequent pattern matches to fail.

This patch fixes this by removing the back slash in that case.

Thanks to Romain Tartière fox reporting this bug.

Test case:

    echo /*"/null"

Old result:

    /*/null

New result:

    /dev/null

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'src')
-rw-r--r--src/expand.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/expand.c b/src/expand.c
index 2c52781..e4c4c8b 100644
--- a/src/expand.c
+++ b/src/expand.c
@@ -1269,10 +1269,11 @@ expmeta(char *enddir, char *name)
 	struct dirent *dp;
 	int atend;
 	int matchdot;
+	int esc;
 
 	metaflag = 0;
 	start = name;
-	for (p = name; *p; p++) {
+	for (p = name; esc = 0, *p; p += esc + 1) {
 		if (*p == '*' || *p == '?')
 			metaflag = 1;
 		else if (*p == '[') {
@@ -1291,11 +1292,11 @@ expmeta(char *enddir, char *name)
 			}
 		} else {
 			if (*p == '\\')
-				p++;
-			if (*p == '/') {
+				esc++;
+			if (p[esc] == '/') {
 				if (metaflag)
 					break;
-				start = p + 1;
+				start = p + esc + 1;
 			}
 		}
 	}
@@ -1337,7 +1338,8 @@ expmeta(char *enddir, char *name)
 		atend = 1;
 	} else {
 		atend = 0;
-		*endname++ = '\0';
+		*endname = '\0';
+		endname += esc + 1;
 	}
 	matchdot = 0;
 	p = start;
@@ -1363,7 +1365,7 @@ expmeta(char *enddir, char *name)
 	}
 	closedir(dirp);
 	if (! atend)
-		endname[-1] = '/';
+		endname[-esc - 1] = esc ? '\\' : '/';
 }
 #endif	/* HAVE_GLOB */
 
olspan='3' class='logmsg'> 2019-12-22Export In-Reply-To headersJune McEnroe 2019-12-21Add git-fetch-email to READMEJune McEnroe 2019-12-21Clarify purpose in READMEJune McEnroe 2019-12-21Add READMEJune McEnroe 2019-12-21Add copyright header to git-fetch-emailJune McEnroe 2019-12-21Add git-fetch-email to SEE ALSO of imboxJune McEnroe 2019-12-21Add git-fetch-email wrapperJune McEnroe 2019-12-21Determine host by SRV lookupJune McEnroe 2019-12-21Clean up remaining codeJune McEnroe 2019-12-21Clean up mboxrd codeJune McEnroe 2019-12-21Convert CRLF to LFJune McEnroe 2019-12-21Implement -CFSTJune McEnroe 2019-12-21Rewrite aspirational manualJune McEnroe 2019-12-21Null-terminate read literalsJune McEnroe