apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wr...@apache.org
Subject svn commit: r1103049 - /apr/apr/branches/1.5.x/strings/apr_fnmatch.c
Date Sat, 14 May 2011 11:26:09 GMT
Author: wrowe
Date: Sat May 14 11:26:08 2011
New Revision: 1103049

URL: http://svn.apache.org/viewvc?rev=1103049&view=rev
Log:
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

Modified:
    apr/apr/branches/1.5.x/strings/apr_fnmatch.c

Modified: apr/apr/branches/1.5.x/strings/apr_fnmatch.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.5.x/strings/apr_fnmatch.c?rev=1103049&r1=1103048&r2=1103049&view=diff
==============================================================================
--- apr/apr/branches/1.5.x/strings/apr_fnmatch.c (original)
+++ apr/apr/branches/1.5.x/strings/apr_fnmatch.c Sat May 14 11:26:08 2011
@@ -116,17 +116,22 @@ static APR_INLINE int fnmatch_ch(const c
                 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;
     }



Mime
View raw message