2
0
mirror of https://github.com/sudo-project/sudo.git synced 2025-08-30 05:48:18 +00:00

Fix fnmatch and glob tests to not use hard-coded flag values in the

input file.  Link test programs with libreplace so we get our
replacement verions as needed.
This commit is contained in:
Todd C. Miller 2011-04-06 10:57:39 -04:00
parent 698c5002d1
commit f949dbcc58
5 changed files with 75 additions and 23 deletions

View File

@ -65,11 +65,17 @@ libreplace.la: $(LTLIBOBJS)
./mksiglist: $(srcdir)/mksiglist.c $(srcdir)/mksiglist.h $(incdir)/missing.h $(top_builddir)/config.h
$(CC) $(CPPFLAGS) $(CFLAGS) $(DEFS) $(srcdir)/mksiglist.c -o $@
fnm_test: $(srcdir)/regress/fnmatch/fnm_test.c
$(CC) $(CPPFLAGS) $(CFLAGS) $(DEFS) $(srcdir)/regress/fnmatch/fnm_test.c -o $@
fnm_test.o: $(srcdir)/regress/fnmatch/fnm_test.c
$(CC) -c $(CPPFLAGS) $(CFLAGS) $(DEFS) $(srcdir)/regress/fnmatch/fnm_test.c
globtest: $(srcdir)/regress/glob/globtest.c
$(CC) $(CPPFLAGS) $(CFLAGS) $(DEFS) $(srcdir)/regress/glob/globtest.c -o $@
fnm_test: fnm_test.o libreplace.la
$(LIBTOOL) --mode=link $(CC) -o $@ fnm_test.o libreplace.la
globtest.o: $(srcdir)/regress/glob/globtest.c
$(CC) -c $(CPPFLAGS) $(CFLAGS) $(DEFS) $(srcdir)/regress/glob/globtest.c
globtest: globtest.o libreplace.la
$(LIBTOOL) --mode=link $(CC) -o $@ globtest.o libreplace.la
@DEV@$(srcdir)/mksiglist.h: $(srcdir)/siglist.in
@DEV@ awk 'BEGIN {print "/* public domain */\n"} /^ [A-Z]/ {printf("#ifdef SIG%s\n if (my_sys_siglist[SIG%s] == NULL)\n\tmy_sys_siglist[SIG%s] = \"%s\";\n#endif\n", $$1, $$1, $$1, substr($$0, 13))}' < $(srcdir)/siglist.in > $@

View File

@ -8,6 +8,12 @@
#include <stdio.h>
#include <stdlib.h>
#ifdef HAVE_STRING_H
# include <string.h>
#endif /* HAVE_STRING_H */
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif /* HAVE_STRINGS_H */
#ifdef HAVE_FNMATCH
# include <fnmatch.h>
#else
@ -18,7 +24,7 @@ int
main(int argc, char *argv[])
{
FILE *fp = stdin;
char pattern[1024], string[1024];
char pattern[1024], string[1024], flagstr[1024];
int errors = 0, tests = 0, flags, got, want;
if (argc > 1) {
@ -35,11 +41,22 @@ main(int argc, char *argv[])
*
*/
for (;;) {
got = fscanf(fp, "%s %s 0x%x %d\n", pattern, string, &flags,
got = fscanf(fp, "%s %s %s %d\n", pattern, string, flagstr,
&want);
if (got == EOF)
break;
if (got == 4) {
flags = 0;
if (strcmp(flagstr, "FNM_NOESCAPE") == 0)
flags |= FNM_NOESCAPE;
else if (strcmp(flagstr, "FNM_PATHNAME") == 0)
flags |= FNM_PATHNAME;
else if (strcmp(flagstr, "FNM_PERIOD") == 0)
flags |= FNM_PERIOD;
else if (strcmp(flagstr, "FNM_LEADING_DIR") == 0)
flags |= FNM_LEADING_DIR;
else if (strcmp(flagstr, "FNM_CASEFOLD") == 0)
flags |= FNM_CASEFOLD;
got = fnmatch(pattern, string, flags);
if (got != want) {
fprintf(stderr,

View File

@ -1,5 +1,5 @@
/bin/[[:alpha:][:alnum:]]* /bin/ls 0x2 0
/bin/[[:upper:]][[:alnum:]] /bin/ls 0x10 0
/bin/[[:opper:][:alnum:]]* /bin/ls 0x0 1
[[:alpha:][:alnum:]]*.c foo1.c 0x4 0
[[:upper:]]* FOO 0x0 0
/bin/[[:alpha:][:alnum:]]* /bin/ls FNM_PATHNAME 0
/bin/[[:upper:]][[:alnum:]] /bin/ls FNM_CASEFOLD 0
/bin/[[:opper:][:alnum:]]* /bin/ls NONE 1
[[:alpha:][:alnum:]]*.c foo1.c FNM_PERIOD 0
[[:upper:]]* FOO NONE 0

View File

@ -19,9 +19,14 @@
#else
# include "compat/glob.h"
#endif
#include <errno.h>
#define MAX_RESULTS 256
#ifndef errno
extern int errno;
#endif
struct gl_entry {
int flags;
int nresults;
@ -104,17 +109,40 @@ main(int argc, char **argv)
lineno);
exit(1);
}
entry.flags = (int)strtol(cp, &ep, 0);
if (*ep != '>') {
ep = strchr(cp, '>');
if (ep == NULL) {
fprintf(stderr,
"globtest: invalid entry on line %d\n",
lineno);
exit(1);
}
if (entry.flags < 0 || entry.flags > 0x2000) {
fprintf(stderr,
"globtest: invalid flags: %s\n", cp);
exit(1);
*ep = '\0';
entry.flags = 0;
for ((cp = strtok(cp, "|")); cp != NULL; (cp = strtok(NULL, "|"))) {
if (strcmp(cp, "GLOB_APPEND") == 0)
entry.flags |= GLOB_APPEND;
else if (strcmp(cp, "GLOB_DOOFFS") == 0)
entry.flags |= GLOB_DOOFFS;
else if (strcmp(cp, "GLOB_ERR") == 0)
entry.flags |= GLOB_ERR;
else if (strcmp(cp, "GLOB_MARK") == 0)
entry.flags |= GLOB_MARK;
else if (strcmp(cp, "GLOB_NOCHECK") == 0)
entry.flags |= GLOB_NOCHECK;
else if (strcmp(cp, "GLOB_NOSORT") == 0)
entry.flags |= GLOB_NOSORT;
else if (strcmp(cp, "GLOB_NOESCAPE") == 0)
entry.flags |= GLOB_NOESCAPE;
else if (strcmp(cp, "GLOB_BRACE") == 0)
entry.flags |= GLOB_BRACE;
else if (strcmp(cp, "GLOB_TILDE") == 0)
entry.flags |= GLOB_TILDE;
else if (strcmp(cp, "NONE") != 0) {
fprintf(stderr,
"globtest: invalid flags on line %d\n",
lineno);
exit(1);
}
}
entry.nresults = 0;
continue;
@ -151,7 +179,8 @@ int test_glob(struct gl_entry *entry)
int i = 0;
if (glob(entry->pattern, entry->flags, NULL, &gl) != 0) {
fprintf(stderr, "glob failed: %s", entry->pattern);
fprintf(stderr, "glob failed: %s: %s\n", entry->pattern,
strerror(errno));
exit(1);
}

View File

@ -1,4 +1,4 @@
[fake/bin/[[:alpha:]]*] <0x0>
[fake/bin/[[:alpha:]]*] <NONE>
fake/bin/cat
fake/bin/chgrp
fake/bin/chio
@ -46,19 +46,19 @@ fake/bin/systrace
fake/bin/tar
fake/bin/test
[fake/bin/rm{,dir,ail}] <0x80>
[fake/bin/rm{,dir,ail}] <GLOB_BRACE>
fake/bin/rm
fake/bin/rmdir
fake/bin/rmail
[fake/bin/sha[[:digit:]]] <0x0>
[fake/bin/sha[[:digit:]]] <NONE>
fake/bin/sha1
[fake/bin/sha[[:digit:]]*] <0x0>
[fake/bin/sha[[:digit:]]*] <NONE>
fake/bin/sha1
fake/bin/sha256
fake/bin/sha384
fake/bin/sha512
[fake/bin/ca[a-z]] <0x0>
[fake/bin/ca[a-z]] <NONE>
fake/bin/cat