mirror of
https://github.com/sudo-project/sudo.git
synced 2025-08-30 22:05:46 +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:
@@ -65,11 +65,17 @@ libreplace.la: $(LTLIBOBJS)
|
|||||||
./mksiglist: $(srcdir)/mksiglist.c $(srcdir)/mksiglist.h $(incdir)/missing.h $(top_builddir)/config.h
|
./mksiglist: $(srcdir)/mksiglist.c $(srcdir)/mksiglist.h $(incdir)/missing.h $(top_builddir)/config.h
|
||||||
$(CC) $(CPPFLAGS) $(CFLAGS) $(DEFS) $(srcdir)/mksiglist.c -o $@
|
$(CC) $(CPPFLAGS) $(CFLAGS) $(DEFS) $(srcdir)/mksiglist.c -o $@
|
||||||
|
|
||||||
fnm_test: $(srcdir)/regress/fnmatch/fnm_test.c
|
fnm_test.o: $(srcdir)/regress/fnmatch/fnm_test.c
|
||||||
$(CC) $(CPPFLAGS) $(CFLAGS) $(DEFS) $(srcdir)/regress/fnmatch/fnm_test.c -o $@
|
$(CC) -c $(CPPFLAGS) $(CFLAGS) $(DEFS) $(srcdir)/regress/fnmatch/fnm_test.c
|
||||||
|
|
||||||
globtest: $(srcdir)/regress/glob/globtest.c
|
fnm_test: fnm_test.o libreplace.la
|
||||||
$(CC) $(CPPFLAGS) $(CFLAGS) $(DEFS) $(srcdir)/regress/glob/globtest.c -o $@
|
$(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@$(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 > $@
|
@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 > $@
|
||||||
|
@@ -8,6 +8,12 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.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
|
#ifdef HAVE_FNMATCH
|
||||||
# include <fnmatch.h>
|
# include <fnmatch.h>
|
||||||
#else
|
#else
|
||||||
@@ -18,7 +24,7 @@ int
|
|||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
FILE *fp = stdin;
|
FILE *fp = stdin;
|
||||||
char pattern[1024], string[1024];
|
char pattern[1024], string[1024], flagstr[1024];
|
||||||
int errors = 0, tests = 0, flags, got, want;
|
int errors = 0, tests = 0, flags, got, want;
|
||||||
|
|
||||||
if (argc > 1) {
|
if (argc > 1) {
|
||||||
@@ -35,11 +41,22 @@ main(int argc, char *argv[])
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
for (;;) {
|
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);
|
&want);
|
||||||
if (got == EOF)
|
if (got == EOF)
|
||||||
break;
|
break;
|
||||||
if (got == 4) {
|
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);
|
got = fnmatch(pattern, string, flags);
|
||||||
if (got != want) {
|
if (got != want) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/bin/[[:alpha:][:alnum:]]* /bin/ls 0x2 0
|
/bin/[[:alpha:][:alnum:]]* /bin/ls FNM_PATHNAME 0
|
||||||
/bin/[[:upper:]][[:alnum:]] /bin/ls 0x10 0
|
/bin/[[:upper:]][[:alnum:]] /bin/ls FNM_CASEFOLD 0
|
||||||
/bin/[[:opper:][:alnum:]]* /bin/ls 0x0 1
|
/bin/[[:opper:][:alnum:]]* /bin/ls NONE 1
|
||||||
[[:alpha:][:alnum:]]*.c foo1.c 0x4 0
|
[[:alpha:][:alnum:]]*.c foo1.c FNM_PERIOD 0
|
||||||
[[:upper:]]* FOO 0x0 0
|
[[:upper:]]* FOO NONE 0
|
||||||
|
@@ -19,9 +19,14 @@
|
|||||||
#else
|
#else
|
||||||
# include "compat/glob.h"
|
# include "compat/glob.h"
|
||||||
#endif
|
#endif
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
#define MAX_RESULTS 256
|
#define MAX_RESULTS 256
|
||||||
|
|
||||||
|
#ifndef errno
|
||||||
|
extern int errno;
|
||||||
|
#endif
|
||||||
|
|
||||||
struct gl_entry {
|
struct gl_entry {
|
||||||
int flags;
|
int flags;
|
||||||
int nresults;
|
int nresults;
|
||||||
@@ -104,17 +109,40 @@ main(int argc, char **argv)
|
|||||||
lineno);
|
lineno);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
entry.flags = (int)strtol(cp, &ep, 0);
|
ep = strchr(cp, '>');
|
||||||
if (*ep != '>') {
|
if (ep == NULL) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"globtest: invalid entry on line %d\n",
|
"globtest: invalid entry on line %d\n",
|
||||||
lineno);
|
lineno);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
if (entry.flags < 0 || entry.flags > 0x2000) {
|
*ep = '\0';
|
||||||
fprintf(stderr,
|
entry.flags = 0;
|
||||||
"globtest: invalid flags: %s\n", cp);
|
for ((cp = strtok(cp, "|")); cp != NULL; (cp = strtok(NULL, "|"))) {
|
||||||
exit(1);
|
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;
|
entry.nresults = 0;
|
||||||
continue;
|
continue;
|
||||||
@@ -151,7 +179,8 @@ int test_glob(struct gl_entry *entry)
|
|||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
if (glob(entry->pattern, entry->flags, NULL, &gl) != 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);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
[fake/bin/[[:alpha:]]*] <0x0>
|
[fake/bin/[[:alpha:]]*] <NONE>
|
||||||
fake/bin/cat
|
fake/bin/cat
|
||||||
fake/bin/chgrp
|
fake/bin/chgrp
|
||||||
fake/bin/chio
|
fake/bin/chio
|
||||||
@@ -46,19 +46,19 @@ fake/bin/systrace
|
|||||||
fake/bin/tar
|
fake/bin/tar
|
||||||
fake/bin/test
|
fake/bin/test
|
||||||
|
|
||||||
[fake/bin/rm{,dir,ail}] <0x80>
|
[fake/bin/rm{,dir,ail}] <GLOB_BRACE>
|
||||||
fake/bin/rm
|
fake/bin/rm
|
||||||
fake/bin/rmdir
|
fake/bin/rmdir
|
||||||
fake/bin/rmail
|
fake/bin/rmail
|
||||||
|
|
||||||
[fake/bin/sha[[:digit:]]] <0x0>
|
[fake/bin/sha[[:digit:]]] <NONE>
|
||||||
fake/bin/sha1
|
fake/bin/sha1
|
||||||
|
|
||||||
[fake/bin/sha[[:digit:]]*] <0x0>
|
[fake/bin/sha[[:digit:]]*] <NONE>
|
||||||
fake/bin/sha1
|
fake/bin/sha1
|
||||||
fake/bin/sha256
|
fake/bin/sha256
|
||||||
fake/bin/sha384
|
fake/bin/sha384
|
||||||
fake/bin/sha512
|
fake/bin/sha512
|
||||||
|
|
||||||
[fake/bin/ca[a-z]] <0x0>
|
[fake/bin/ca[a-z]] <NONE>
|
||||||
fake/bin/cat
|
fake/bin/cat
|
||||||
|
Reference in New Issue
Block a user