tests: fixes to accomodate growing OPEN_MAX and a logic error

This commit is contained in:
Ben Gras 2010-07-13 12:38:58 +00:00
parent 60549b67be
commit 835232d504
2 changed files with 77 additions and 45 deletions

View File

@ -13,6 +13,7 @@
#include <utime.h> #include <utime.h>
#include <stdio.h> #include <stdio.h>
#include <limits.h> #include <limits.h>
#include <assert.h>
#define NOCRASH 1 /* test11(), 2nd pipe */ #define NOCRASH 1 /* test11(), 2nd pipe */
#define PDPNOHANG 1 /* test03(), write_standards() */ #define PDPNOHANG 1 /* test03(), write_standards() */
@ -62,18 +63,15 @@
int errct; int errct;
char *file[];
char *fnames[];
char *dir[];
/* "decl.c", created by Rene Montsma and Menno Wilcke */ /* "decl.c", created by Rene Montsma and Menno Wilcke */
/* Used in open_alot, close_alot */ /* Used in open_alot, close_alot */
char *file[20] = {"f0", "f1", "f2", "f3", "f4", "f5", "f6", char *filenames[MAXOPEN];
"f7", "f8", "f9", "f10", "f11", "f12", "f13",
"f14", "f15", "f16", "f17", "f18", "f19"}, *fnames[8] = {"---", "--x", "-w-", "-wx", "r--", #define MODES 8
"r-x", "rw-", "rwx"}, *dir[8] = {"d---", "d--x", "d-w-", "d-wx", "dr--", "dr-x", char *mode_fnames[MODES] = {"---", "--x", "-w-", "-wx", "r--", "r-x", "rw-", "rwx"},
"drw-", "drwx"}; *mode_dir[MODES] = {"d---", "d--x", "d-w-", "d-wx", "dr--", "dr-x", "drw-", "drwx"};
/* Needed for easy creating and deleting of directories */ /* Needed for easy creating and deleting of directories */
/* "test.c", created by Rene Montsma and Menno Wilcke */ /* "test.c", created by Rene Montsma and Menno Wilcke */
@ -120,7 +118,15 @@ int argc;
char *argv[]; char *argv[];
{ {
char buffer[PATH_MAX + 1]; char buffer[PATH_MAX + 1];
int n, mask; int n, mask, i;
/* Create filenames for MAXOPEN files, the *filenames[] array. */
for(i = 0; i < MAXOPEN; i++) {
if(asprintf(&filenames[i], "file%d", i) == -1) {
fprintf(stderr, "asprintf failed\n");
return 1;
}
}
sync(); sync();
if (geteuid() == 0 || getuid() == 0) { if (geteuid() == 0 || getuid() == 0) {
@ -130,8 +136,18 @@ char *argv[];
exit(1); exit(1);
} }
system("rm -rf DIR_17; mkdir DIR_17"); #define DIR "DIR17"
chdir("DIR_17"); system("rm -rf " DIR);
if(mkdir(DIR, 0755) != 0) {
perror("mkdir");
return 1;
}
if(chdir(DIR) < 0) {
perror("chdir");
return 1;
}
mask = (argc == 2 ? atoi(argv[1]) : 0xFFFF); mask = (argc == 2 ? atoi(argv[1]) : 0xFFFF);
@ -219,17 +235,16 @@ void test02()
mode = 0; mode = 0;
/* Create twenty files, check filedes */ /* Create twenty files, check filedes */
for (n = 0; n < MAXOPEN; n++) { for (n = 0; n < MAXOPEN; n++) {
if (creat(file[n], mode) != FF + n) if (creat(filenames[n], mode) != FF + n)
err(13, CREAT, file[n]); err(13, CREAT, filenames[n]);
else { else {
if (get_mode(file[n]) != mode) if (get_mode(filenames[n]) != mode)
err(7, CREAT, "mode set while creating many files"); err(7, CREAT, "mode set while creating many files");
/* Change mode of file to standard mode, we want to * /* Change mode of file to standard mode, we want to *
* use a lot (20) of files to be opened later, see * * use a lot (20) of files to be opened later, see *
* open_alot(), close_alot(). */ * open_alot(), close_alot(). */
if (chmod(file[n], 0700) != OK) err(5, CHMOD, file[n]); if (chmod(filenames[n], 0700) != OK) err(5, CHMOD, filenames[n]);
} }
mode = (mode + 0100) % 01000; mode = (mode + 0100) % 01000;
} }
@ -452,7 +467,7 @@ void test10()
int n, n1; int n, n1;
char a[ARSIZE], b[ARSIZE], *f, *lf; char a[ARSIZE], b[ARSIZE], *f, *lf;
f = "file10"; f = "anotherfile10";
lf = "linkfile10"; lf = "linkfile10";
if ((n = creat(f, 0702)) != FF) /* no other open files */ if ((n = creat(f, 0702)) != FF) /* no other open files */
@ -874,9 +889,9 @@ void make_and_fill_dirs()
{ {
int mode, i; int mode, i;
for (i = 0; i < 8; i++) { for (i = 0; i < MODES; i++) {
mkdir(dir[i], 0700); mkdir(mode_dir[i], 0700);
chown(dir[i], USER_ID, GROUP_ID); chown(mode_dir[i], USER_ID, GROUP_ID);
} }
setuid(USER_ID); setuid(USER_ID);
setgid(GROUP_ID); setgid(GROUP_ID);
@ -902,10 +917,12 @@ int mode;
err(5, CHDIR, "to dirname (put_f_in_dir)"); err(5, CHDIR, "to dirname (put_f_in_dir)");
else { else {
/* Creat the file */ /* Creat the file */
if ((nr = creat(fnames[mode], mode * 0100)) < 0) assert(mode >= 0 && mode < MODES);
err(13, CREAT, fnames[mode]); if ((nr = creat(mode_fnames[mode], mode * 0100)) < 0)
else err(13, CREAT, mode_fnames[mode]);
try_close(nr, fnames[mode]); else {
try_close(nr, mode_fnames[mode]);
}
if (chdir("..") != OK) if (chdir("..") != OK)
err(5, CHDIR, "to previous dir (put_f_in_dir)"); err(5, CHDIR, "to previous dir (put_f_in_dir)");
@ -1065,7 +1082,7 @@ int open_alot()
int i; int i;
for (i = 0; i < MAXOPEN; i++) for (i = 0; i < MAXOPEN; i++)
if (open(file[i], R) == FAIL) break; if (open(filenames[i], R) == FAIL) break;
if (i == 0) err(5, "open_alot", "at all"); if (i == 0) err(5, "open_alot", "at all");
return(i); return(i);
} /* open_alot */ } /* open_alot */
@ -1096,13 +1113,17 @@ void clean_up_the_mess()
char dirname[6]; char dirname[6];
/* First remove 'a lot' files */ /* First remove 'a lot' files */
for (i = 0; i < MAXOPEN; i++) try_unlink(file[i]); for (i = 0; i < MAXOPEN; i++) {
try_unlink(filenames[i]);
}
/* Unlink the files in dir 'drwx' */ /* Unlink the files in dir 'drwx' */
if (chdir("drwx") != OK) if (chdir("drwx") != OK)
err(5, CHDIR, "to 'drwx'"); err(5, CHDIR, "to 'drwx'");
else { else {
for (i = 0; i < 8; i++) try_unlink(fnames[i]); for (i = 0; i < MODES; i++) {
try_unlink(mode_fnames[i]);
}
if (chdir("..") != OK) err(5, CHDIR, "to '..'"); if (chdir("..") != OK) err(5, CHDIR, "to '..'");
} }
@ -1115,9 +1136,9 @@ void clean_up_the_mess()
try_unlink("drw-/rwx"); try_unlink("drw-/rwx");
/* Unlink dirs */ /* Unlink dirs */
for (i = 0; i < 8; i++) { for (i = 0; i < MODES; i++) {
strcpy(dirname, "d"); strcpy(dirname, "d");
strcat(dirname, fnames[i]); strcat(dirname, mode_fnames[i]);
/* 'dirname' contains the directoryname */ /* 'dirname' contains the directoryname */
rmdir(dirname); rmdir(dirname);
@ -1138,8 +1159,8 @@ int sw; /* if switch == 8, give all different
else else
mode = sw; mode = sw;
for (i = 0; i < 8; i++) { for (i = 0; i < MODES; i++) {
chmod(dir[i], 040000 + mode * 0100); chmod(mode_dir[i], 040000 + mode * 0100);
if (sw == 8) mode++; if (sw == 8) mode++;
} }
} }

View File

@ -66,18 +66,13 @@
int errct; int errct;
char *file[];
char *fnames[];
char *dir[];
/* "decl.c", created by Rene Montsma and Menno Wilcke */ /* "decl.c", created by Rene Montsma and Menno Wilcke */
/* Used in open_alot, close_alot */ /* Used in open_alot, close_alot */
char *file[20] = {"f0", "f1", "f2", "f3", "f4", "f5", "f6", char *file[MAXOPEN];
"f7", "f8", "f9", "f10", "f11", "f12", "f13", char *fnames[8] = {"---", "--x", "-w-", "-wx", "r--", "r-x", "rw-", "rwx"},
"f14", "f15", "f16", "f17", "f18", "f19"}, *fnames[8] = {"---", "--x", "-w-", "-wx", "r--", *dir[8] = {"d---", "d--x", "d-w-", "d-wx", "dr--", "dr-x", "drw-", "drwx"};
"r-x", "rw-", "rwx"}, *dir[8] = {"d---", "d--x", "d-w-", "d-wx", "dr--", "dr-x",
"drw-", "drwx"};
/* Needed for easy creating and deleting of directories */ /* Needed for easy creating and deleting of directories */
/* "test.c", created by Rene Montsma and Menno Wilcke */ /* "test.c", created by Rene Montsma and Menno Wilcke */
@ -130,7 +125,15 @@ _PROTOTYPE(void quit, (void));
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
char buffer[PATH_MAX + 1]; char buffer[PATH_MAX + 1];
int n; int n, i;
/* Create filenames for MAXOPEN files, the *file[] array. */
for(i = 0; i < MAXOPEN; i++) {
if(asprintf(&file[i], "file%d", i) == -1) {
fprintf(stderr, "asprintf failed\n");
return 1;
}
}
if (geteuid() == 0 || getuid() == 0) { if (geteuid() == 0 || getuid() == 0) {
realpath(argv[0], buffer); realpath(argv[0], buffer);
@ -139,8 +142,16 @@ int main(int argc, char **argv)
exit(1); exit(1);
} }
system("rm -rf DIR_18; mkdir DIR_18"); #define DIR "DIR18"
chdir("DIR_18"); system("rm -rf " DIR);
if(mkdir(DIR, 0755) != 0) {
perror("mkdir");
return 1;
}
if(chdir(DIR) != 0) {
perror("chdir");
return 1;
}
if (fork()) { if (fork()) {
printf("Test 18 "); printf("Test 18 ");
@ -645,7 +656,7 @@ void test05()
check(OPEN, ENOENT); check(OPEN, ENOENT);
/* Dir is not searchable */ /* Dir is not searchable */
if (n = open("drw-/rwx", R) != FAIL) if ((n = open("drw-/rwx", R)) != FAIL)
err(11, OPEN, "open in an non-searchabledir"); err(11, OPEN, "open in an non-searchabledir");
else else
check(OPEN, EACCES); check(OPEN, EACCES);