On Wed, Dec 07, 2011 at 03:38:05PM -0800, William A. Rowe Jr. wrote: > On 12/7/2011 1:12 PM, Stefan Sperling wrote: > > Can the classmatch bits go in without this strnlen check in the meantime? > > As long as the appropriate change is made to NOTICE, I am +1, > the license appears group-A fully compatible.
You mean the LICENSE file, not NOTICE, right? The ISC licence has no advertising clause. And I just noted that LICENSE still lists the old Berkeley copyright notice for apr_fnmatch.c, from before your rewrite. Index: strings/charclass.h =================================================================== --- strings/charclass.h (revision 0) +++ strings/charclass.h (working copy) @@ -0,0 +1,29 @@ +/* + * Public domain, 2008, Todd C. Miller <[email protected]> + * + * $OpenBSD: charclass.h,v 1.1 2008/10/01 23:04:13 millert Exp $ + */ + +/* + * POSIX character class support for fnmatch() and glob(). + */ +static struct cclass { + const char *name; + int (*isctype)(int); +} cclasses[] = { + { "alnum", isalnum }, + { "alpha", isalpha }, + { "blank", isblank }, + { "cntrl", iscntrl }, + { "digit", isdigit }, + { "graph", isgraph }, + { "lower", islower }, + { "print", isprint }, + { "punct", ispunct }, + { "space", isspace }, + { "upper", isupper }, + { "xdigit", isxdigit }, + { NULL, NULL } +}; + +#define NCCLASSES (sizeof(cclasses) / sizeof(cclasses[0]) - 1) Index: strings/apr_fnmatch.c =================================================================== --- strings/apr_fnmatch.c (revision 1210859) +++ strings/apr_fnmatch.c (working copy) @@ -14,6 +14,21 @@ * limitations under the License. */ +/* + * Copyright (c) 2008 Todd C. Miller <[email protected]> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ /* Derived from The Open Group Base Specifications Issue 7, IEEE Std 1003.1-2008 * as described in; @@ -63,7 +78,52 @@ # include <ctype.h> #endif +#include "charclass.h" +#define RANGE_MATCH 1 +#define RANGE_NOMATCH 0 +#define RANGE_ERROR (-1) + +static int +classmatch(const char *pattern, char test, int foldcase, const char **ep) +{ + struct cclass *cc; + const char *colon; + size_t len; + int rval = RANGE_NOMATCH; + const char * const mismatch = pattern; + + if (*pattern != '[' || pattern[1] != ':') { + *ep = mismatch; + return(RANGE_ERROR); + } + + pattern += 2; + + if ((colon = strchr(pattern, ':')) == NULL || colon[1] != ']') { + *ep = mismatch; + return(RANGE_ERROR); + } + *ep = colon + 2; + len = (size_t)(colon - pattern); + + if (foldcase && strncmp(pattern, "upper:]", 7) == 0) + pattern = "lower:]"; + for (cc = cclasses; cc->name != NULL; cc++) { + if (!strncmp(pattern, cc->name, len) && cc->name[len] == '\0') { + if (cc->isctype((unsigned char)test)) + rval = RANGE_MATCH; + break; + } + } + if (cc->name == NULL) { + /* invalid character class, treat as normal text */ + *ep = mismatch; + rval = RANGE_ERROR; + } + return(rval); +} + /* Most MBCS/collation/case issues handled here. Wildcard '*' is not handled. * EOS '\0' and the FNM_PATHNAME '/' delimiters are not advanced over, * however the "\/" sequence is advanced to '/'. @@ -115,6 +175,13 @@ static APR_INLINE int fnmatch_ch(const char **patt if (slash && (**pattern == '/')) break; + /* Match character classes. */ + if (classmatch(*pattern, **string, nocase, pattern) + == RANGE_MATCH) { + result = 0; + continue; + } + leadingclosebrace: /* Look at only well-formed range patterns; * "x-]" is not allowed unless escaped ("x-\]") Index: LICENSE =================================================================== --- LICENSE (revision 1210859) +++ LICENSE (working copy) @@ -209,8 +209,8 @@ separate copyright notices and license terms. Your code for these subcomponents is subject to the terms and conditions of the following licenses. -From strings/apr_fnmatch.c, include/apr_fnmatch.h, misc/unix/getopt.c, -file_io/unix/mktemp.c, strings/apr_strings.c: +From include/apr_fnmatch.h, misc/unix/getopt.c, file_io/unix/mktemp.c, +strings/apr_strings.c: /* * Copyright (c) 1987, 1993, 1994 @@ -338,4 +338,18 @@ From strings/apr_snprintf.c: ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +From strings/apr_fnmatch.c: + * Copyright (c) 2008 Todd C. Miller <[email protected]> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
