diff options
author | wrowe <wrowe@13f79535-47bb-0310-9956-ffa450edef68> | 2011-05-14 11:26:19 +0000 |
---|---|---|
committer | wrowe <wrowe@13f79535-47bb-0310-9956-ffa450edef68> | 2011-05-14 11:26:19 +0000 |
commit | 5df0de3d9d00bcedbfd2de8e9864c40463d74aa1 (patch) | |
tree | 5da7cdf7478284b598027c9ac343c1517d01caef | |
parent | ed1ebb7baec057aeed1c369ce52e0754a8563231 (diff) | |
download | libapr-5df0de3d9d00bcedbfd2de8e9864c40463d74aa1.tar.gz |
Fix another edge case, in [x-/] processing, which I can't seem
to compose the proper test-case to expose.
Refactor a complex test into a very simple test and
optimize the exception cases to bust the loop early.
Clean up documentation a bit.
Backports: r1103041, r1103046
git-svn-id: http://svn.apache.org/repos/asf/apr/apr/branches/1.4.x@1103050 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | strings/apr_fnmatch.c | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/strings/apr_fnmatch.c b/strings/apr_fnmatch.c index 06546be1a..eb6aeb01a 100644 --- a/strings/apr_fnmatch.c +++ b/strings/apr_fnmatch.c @@ -116,17 +116,22 @@ static APR_INLINE int fnmatch_ch(const char **pattern, const char **string, int break; leadingclosebrace: - /* Look at only well-formed range patterns; ']' is allowed only if escaped, - * while '/' is not allowed at all in FNM_PATHNAME mode. + /* Look at only well-formed range patterns; + * "x-]" is not allowed unless escaped ("x-\]") */ /* XXX: Fix for locale/MBCS character width */ - if (((*pattern)[1] == '-') && (*pattern)[2] - && ((escape && ((*pattern)[2] != '\\')) - ? (((*pattern)[2] != ']') && (!slash || ((*pattern)[2] != '/'))) - : (((*pattern)[3]) && (!slash || ((*pattern)[3] != '/'))))) { + if (((*pattern)[1] == '-') && ((*pattern)[2] != ']')) + { startch = *pattern; *pattern += (escape && ((*pattern)[2] == '\\')) ? 3 : 2; + /* NOT a properly balanced [expr] pattern, EOS terminated + * or ranges containing a slash in FNM_PATHNAME mode pattern + * fall out to to the rewind and test '[' literal code path + */ + if (!**pattern || (slash && (**pattern == '\\'))) + break; + /* XXX: handle locale/MBCS comparison, advance by MBCS char width */ if ((**string >= *startch) && (**string <= **pattern)) result = 0; @@ -150,7 +155,9 @@ leadingclosebrace: ++*pattern; } - /* NOT a properly balanced [expr] pattern; Rewind to test '[' literal */ + /* NOT a properly balanced [expr] pattern; Rewind + * and reset result to test '[' literal + */ *pattern = mismatch; result = APR_FNM_NOMATCH; } |