From: Joerg Sonnenberger Date: Tue, 26 May 2009 12:32:48 +0000 (-0400) Subject: Push skipping leading slashes in patterns into pathmatch. X-Git-Tag: v2.8.0~628 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3c30a520c5b91c1fddb4be49dea1ff7b523e2196;p=thirdparty%2Flibarchive.git Push skipping leading slashes in patterns into pathmatch. Skip all leading slashes when doing so. SVN-Revision: 1116 --- diff --git a/cpio/matching.c b/cpio/matching.c index 83efa50f1..2e244c445 100644 --- a/cpio/matching.c +++ b/cpio/matching.c @@ -123,15 +123,15 @@ static void add_pattern(struct match **list, const char *pattern) { struct match *match; + size_t len; - match = malloc(sizeof(*match) + strlen(pattern) + 1); + len = strlen(pattern); + match = malloc(sizeof(*match) + len + 1); if (match == NULL) cpio_errc(1, errno, "Out of memory"); - if (pattern[0] == '/') - pattern++; strcpy(match->pattern, pattern); /* Both "foo/" and "foo" should match "foo/bar". */ - if (match->pattern[strlen(match->pattern)-1] == '/') + if (len && match->pattern[len - 1] == '/') match->pattern[strlen(match->pattern)-1] = '\0'; match->next = *list; *list = match; diff --git a/cpio/pathmatch.c b/cpio/pathmatch.c index 40fa83604..407dae947 100644 --- a/cpio/pathmatch.c +++ b/cpio/pathmatch.c @@ -230,8 +230,11 @@ pathmatch(const char *p, const char *s, int flags) } /* Certain patterns anchor implicitly. */ - if (*p == '*' || *p == '/') + if (*p == '*' || *p == '/') { + while (*p == '/') + ++p; return (pm(p, s, flags)); + } /* If start is unanchored, try to match start of each path element. */ if (flags & PATHMATCH_NO_ANCHOR_START) {