ATF_TC_BODY(msgctl_err, tc) { const int cmd[] = { IPC_STAT, IPC_SET, IPC_RMID }; struct msqid_ds msgds; size_t i; int id; (void)memset(&msgds, 0, sizeof(struct msqid_ds)); id = msgget(MSG_KEY, IPC_CREAT | 0600); ATF_REQUIRE(id != -1); errno = 0; ATF_REQUIRE_ERRNO(EINVAL, msgctl(id, INT_MAX, &msgds) == -1); errno = 0; ATF_REQUIRE_ERRNO(EFAULT, msgctl(id, IPC_STAT, (void *)-1) == -1); for (i = 0; i < __arraycount(cmd); i++) { errno = 0; ATF_REQUIRE_ERRNO(EINVAL, msgctl(-1, cmd[i], &msgds) == -1); } ATF_REQUIRE(msgctl(id, IPC_RMID, 0) == 0); }
ATF_TC_BODY(key, tc) { RZ(rump_init()); RL(open("hostfile", O_RDWR | O_CREAT, 0777)); RZ(rump_pub_etfs_register("/key", "hostfile", RUMP_ETFS_REG)); ATF_REQUIRE_EQ(rump_pub_etfs_register("key", "hostfile", RUMP_ETFS_REG), EINVAL); RL(rump_sys_open("/key", O_RDONLY)); RL(rump_sys_open("////////key", O_RDONLY)); RZ(rump_pub_etfs_register("////key//with/slashes", "hostfile", RUMP_ETFS_REG)); RL(rump_sys_open("/key//with/slashes", O_RDONLY)); RL(rump_sys_open("key//with/slashes", O_RDONLY)); ATF_REQUIRE_ERRNO(ENOENT, rump_sys_open("/key/with/slashes", O_RDONLY) == -1); RL(rump_sys_mkdir("/a", 0777)); ATF_REQUIRE_ERRNO(ENOENT, rump_sys_open("/a/key//with/slashes", O_RDONLY) == -1); }
ATF_TC_BODY(mkfifo_err, tc) { char buf[PATH_MAX + 1]; support(); (void)memset(buf, 'x', sizeof(buf)); ATF_REQUIRE(mkfifo(path, 0600) == 0); errno = 0; ATF_REQUIRE_ERRNO(EFAULT, mkfifo((char *)-1, 0600) == -1); errno = 0; ATF_REQUIRE_ERRNO(EEXIST, mkfifo("/etc/passwd", 0600) == -1); errno = 0; ATF_REQUIRE_ERRNO(EEXIST, mkfifo(path, 0600) == -1); errno = 0; ATF_REQUIRE_ERRNO(ENAMETOOLONG, mkfifo(buf, 0600) == -1); errno = 0; ATF_REQUIRE_ERRNO(ENOENT, mkfifo("/a/b/c/d/e/f/g", 0600) == -1); ATF_REQUIRE(unlink(path) == 0); }
ATF_TC_BODY(write_err, tc) { char rbuf[3] = { 'a', 'b', 'c' }; char wbuf[3] = { 'x', 'y', 'z' }; int fd; errno = 0; ATF_REQUIRE_ERRNO(EBADF, write(-1, wbuf, sizeof(wbuf)) == -1); fd = open(path, O_RDWR | O_CREAT); if (fd >= 0) { errno = 0; ATF_REQUIRE_ERRNO(0, write(fd, wbuf, 3) == 3); errno = 0; ATF_REQUIRE_ERRNO(EINVAL, write(fd, wbuf, SIZE_MAX) == -1); errno = 0; ATF_REQUIRE_ERRNO(EFAULT, write(fd, (void *)-1, 1) == -1); /* * Check that the above bogus write(2) * calls did not corrupt the file. */ ATF_REQUIRE(lseek(fd, 0, SEEK_SET) == 0); ATF_REQUIRE(read(fd, rbuf, 3) == 3); ATF_REQUIRE(memcmp(rbuf, wbuf, 3) == 0); (void)close(fd); (void)unlink(path); } }
ATF_TC_BODY(mknod_err, tc) { char buf[PATH_MAX + 1]; (void)memset(buf, 'x', sizeof(buf)); #ifndef __FreeBSD__ /* * As of FreeBSD 6.0 device nodes may be created in regular file systems but * such nodes cannot be used to access devices. As a result an invalid dev * argument is unchecked. */ errno = 0; ATF_REQUIRE_ERRNO(EINVAL, mknod(path, S_IFCHR, -1) == -1); #endif errno = 0; ATF_REQUIRE_ERRNO(ENAMETOOLONG, mknod(buf, S_IFCHR, 0) == -1); errno = 0; ATF_REQUIRE_ERRNO(EFAULT, mknod((char *)-1, S_IFCHR, 0) == -1); errno = 0; ATF_REQUIRE_ERRNO(ENOENT, mknod("/a/b/c/d/e/f/g", S_IFCHR, 0) == -1); }
ATF_TC_BODY(bigenough, tc) { struct stat sb; RZ(system("rump_server " RUMPSERV)); RL(setenv("RUMP_SERVER", RUMPSERV, 1)); RL(dup2(0, 10)); RL(dup2(1, 11)); RL(dup2(2, 12)); RL(close(0)); RL(close(1)); RL(close(2)); RL(rumpclient_init()); RL(rump_sys_getpid()); ATF_REQUIRE_ERRNO(EBADF, fstat(0, &sb) == -1); ATF_REQUIRE_ERRNO(EBADF, fstat(1, &sb) == -1); ATF_REQUIRE_ERRNO(EBADF, fstat(2, &sb) == -1); RL(rump_sys_getpid()); /* restore these. does it help? */ dup2(10, 0); dup2(11, 1); dup2(12, 2); }
ATF_TC_BODY(msgsnd_err, tc) { struct msg msg = { MSG_MTYPE_1, { 'a', 'b', 'c' } }; int id; id = msgget(MSG_KEY, IPC_CREAT | 0600); ATF_REQUIRE(id != -1); errno = 0; ATF_REQUIRE_ERRNO(EFAULT, msgsnd(id, (void *)-1, sizeof(struct msg), IPC_NOWAIT) == -1); errno = 0; ATF_REQUIRE_ERRNO(EINVAL, msgsnd(-1, &msg, sizeof(struct msg), IPC_NOWAIT) == -1); errno = 0; ATF_REQUIRE_ERRNO(EINVAL, msgsnd(-1, &msg, SSIZE_MAX, IPC_NOWAIT) == -1); errno = 0; msg.mtype = 0; ATF_REQUIRE_ERRNO(EINVAL, msgsnd(id, &msg, sizeof(struct msg), IPC_NOWAIT) == -1); ATF_REQUIRE(msgctl(id, IPC_RMID, 0) == 0); }
void atf_require_errno_semicolons(void) { /* Check that ATF_REQUIRE_ERRNO does not contain a semicolon that would * cause an empty-statement that confuses some compilers. */ ATF_REQUIRE_ERRNO(1, 1 == 1); ATF_REQUIRE_ERRNO(2, 2 == 2); }
ATF_TC_BODY(mknod_perm, tc) { errno = 0; ATF_REQUIRE_ERRNO(EPERM, mknod(path, S_IFCHR, 0) == -1); errno = 0; ATF_REQUIRE_ERRNO(EPERM, mknod(path, S_IFBLK, 0) == -1); }
ATF_TC_BODY(fopen_perm, tc) { errno = 0; ATF_REQUIRE_ERRNO(EACCES, fopen("/bin/ls", "a+") == NULL); errno = 0; ATF_REQUIRE_ERRNO(EACCES, fopen("/bin/ls", "w+") == NULL); }
ATF_TC_BODY(stat_err, tc) { char buf[NAME_MAX + 1]; struct stat st; (void)memset(buf, 'x', sizeof(buf)); errno = 0; ATF_REQUIRE_ERRNO(EBADF, fstat(-1, &st) == -1); errno = 0; ATF_REQUIRE_ERRNO(ENAMETOOLONG, stat(buf, &st) == -1); errno = 0; ATF_REQUIRE_ERRNO(ENAMETOOLONG, lstat(buf, &st) == -1); errno = 0; ATF_REQUIRE_ERRNO(EFAULT, stat((void *)-1, &st) == -1); errno = 0; ATF_REQUIRE_ERRNO(EFAULT, lstat((void *)-1, &st) == -1); errno = 0; ATF_REQUIRE_ERRNO(EFAULT, stat("/etc/passwd", (void *)-1) == -1); errno = 0; ATF_REQUIRE_ERRNO(EFAULT, lstat("/etc/passwd", (void *)-1) == -1); errno = 0; ATF_REQUIRE_ERRNO(ENOENT, stat("/a/b/c/d/e/f/g/h/i/j/k", &st) == -1); errno = 0; ATF_REQUIRE_ERRNO(ENOENT, lstat("/a/b/c/d/e/f/g/h/i/j/k", &st) == -1); }
ATF_TC_BODY(getitimer_err, tc) { struct itimerval it; errno = 0; ATF_REQUIRE_ERRNO(EINVAL, getitimer(-1, &it) == -1); errno = 0; ATF_REQUIRE_ERRNO(EINVAL, getitimer(INT_MAX, &it) == -1); errno = 0; ATF_REQUIRE_ERRNO(EFAULT, getitimer(ITIMER_REAL, (void *)-1) == -1); }
ATF_TC_BODY(rfork, tc) { struct stat sb; struct lwp *l, *l2; int fd; RZ(rump_init()); ATF_REQUIRE_EQ(rump_pub_lwproc_rfork(RUMP_RFFDG|RUMP_RFCFDG), EINVAL); RZ(rump_pub_lwproc_rfork(0)); l = rump_pub_lwproc_curlwp(); RL(fd = rump_sys_open("/file", O_RDWR | O_CREAT, 0777)); /* ok, first check rfork(RUMP_RFCFDG) does *not* preserve fd's */ RZ(rump_pub_lwproc_rfork(RUMP_RFCFDG)); ATF_REQUIRE_ERRNO(EBADF, rump_sys_write(fd, &fd, sizeof(fd)) == -1); /* then check that rfork(0) does */ rump_pub_lwproc_switch(l); RZ(rump_pub_lwproc_rfork(0)); ATF_REQUIRE_EQ(rump_sys_write(fd, &fd, sizeof(fd)), sizeof(fd)); RL(rump_sys_fstat(fd, &sb)); l2 = rump_pub_lwproc_curlwp(); /* * check that the shared fd table is really shared by * closing fd in parent */ rump_pub_lwproc_switch(l); RL(rump_sys_close(fd)); rump_pub_lwproc_switch(l2); ATF_REQUIRE_ERRNO(EBADF, rump_sys_fstat(fd, &sb) == -1); /* redo, this time copying the fd table instead of sharing it */ rump_pub_lwproc_releaselwp(); rump_pub_lwproc_switch(l); RL(fd = rump_sys_open("/file", O_RDWR, 0777)); RZ(rump_pub_lwproc_rfork(RUMP_RFFDG)); ATF_REQUIRE_EQ(rump_sys_write(fd, &fd, sizeof(fd)), sizeof(fd)); RL(rump_sys_fstat(fd, &sb)); l2 = rump_pub_lwproc_curlwp(); /* check that the fd table is copied */ rump_pub_lwproc_switch(l); RL(rump_sys_close(fd)); rump_pub_lwproc_switch(l2); RL(rump_sys_fstat(fd, &sb)); ATF_REQUIRE_EQ(sb.st_size, sizeof(fd)); }
ATF_TC_BODY(ftruncate_err, tc) { int fd; fd = open("/etc/passwd", O_RDONLY, 0400); ATF_REQUIRE(fd >= 0); errno = 0; ATF_REQUIRE_ERRNO(EBADF, ftruncate(-1, 999) == -1); errno = 0; ATF_REQUIRE_ERRNO(EINVAL, ftruncate(fd, 999) == -1); (void)close(fd); }
ATF_TC_BODY(setdomainname_perm, tc) { errno = 0; ATF_REQUIRE_ERRNO(EPERM, setdomainname(domain, sizeof(domain)) == -1); }
ATF_TC_BODY(sethostname_perm, tc) { errno = 0; ATF_REQUIRE_ERRNO(EPERM, sethostname(host, sizeof(host)) == -1); }
ATF_TC_BODY(t_exect_null, tc) { struct sigaction act; /* * Currently exect(3) is misdesigned -- see PR port-amd64/51700 and it * needs to be redone from scratch. * * This test affects amd64 releng machines causing tests to hang or * fail. As there is little point to test interface that is still not, * designed and implemented and is breaking tests - skip it * unconditionally for all ports. */ /* Prevent static analysis from requiring t_exec_null to be __dead. */ if (!caught) atf_tc_skip("exect(3) misdesigned and hangs - PR port-amd64/51700"); ATF_REQUIRE(sigemptyset(&act.sa_mask) == 0); act.sa_sigaction = sigtrap_handler; act.sa_flags = SA_SIGINFO; ATF_REQUIRE(sigaction(SIGTRAP, &act, 0) == 0); ATF_REQUIRE_ERRNO(EFAULT, exect(NULL, NULL, NULL) == -1); ATF_REQUIRE_EQ_MSG(caught, 1, "expected caught (1) != received (%d)", (int)caught); }
static void read_after_unlink(const atf_tc_t *tc, const char *mp) { char buf[TBSIZE], buf2[TBSIZE]; int fd; FSTEST_ENTER(); /* create file and put some content into it */ RL(fd = rump_sys_open("file", O_RDWR|O_CREAT, 0666)); memset(buf, 'D', TBSIZE); ATF_REQUIRE_EQ(rump_sys_write(fd, buf, TBSIZE), TBSIZE); rump_sys_close(fd); /* flush buffers from UBC to file system */ ATF_REQUIRE_ERRNO(EBUSY, rump_sys_unmount(mp, 0) == -1); RL(fd = rump_sys_open("file", O_RDWR)); RL(rump_sys_unlink("file")); ATF_REQUIRE_EQ(rump_sys_read(fd, buf2, TBSIZE), TBSIZE); ATF_REQUIRE_EQ(memcmp(buf, buf2, TBSIZE), 0); rump_sys_close(fd); FSTEST_EXIT(); }
static void dir_rmdirdotdot(const atf_tc_t *tc, const char *mp) { char pb[MAXPATHLEN]; int xerrno; USES_DIRS; FSTEST_ENTER(); RL(rump_sys_mkdir("test", 0777)); RL(rump_sys_chdir("test")); RL(rump_sys_mkdir("subtest", 0777)); RL(rump_sys_chdir("subtest")); md(pb, mp, "test/subtest"); RL(rump_sys_rmdir(pb)); md(pb, mp, "test"); RL(rump_sys_rmdir(pb)); if (FSTYPE_NFS(tc)) xerrno = ESTALE; else xerrno = ENOENT; ATF_REQUIRE_ERRNO(xerrno, rump_sys_chdir("..") == -1); FSTEST_EXIT(); }
ATF_TC_BODY(bad_big5_wprintf, tc) { /* XXX implementation detail knowledge (wchar_t encoding) */ wchar_t ibuf[] = { 0xcf10, 0 }; setlocale(LC_CTYPE, "zh_TW.Big5"); ATF_REQUIRE_ERRNO(EILSEQ, wprintf(L"%ls\n", ibuf) < 0); ATF_REQUIRE(ferror(stdout)); }
ATF_TC_BODY(mlock_err, tc) { #ifdef __NetBSD__ unsigned long vmin = 0; size_t len = sizeof(vmin); #endif void *invalid_ptr; int null_errno = ENOMEM; /* error expected for NULL */ #ifdef __FreeBSD__ #ifdef VM_MIN_ADDRESS if ((uintptr_t)VM_MIN_ADDRESS > 0) null_errno = EINVAL; /* NULL is not inside user VM */ #endif /* Set max_wired really really high to avoid EAGAIN */ set_vm_max_wired(INT_MAX); #else if (sysctlbyname("vm.minaddress", &vmin, &len, NULL, 0) != 0) atf_tc_fail("failed to read vm.minaddress"); if (vmin > 0) null_errno = EINVAL; /* NULL is not inside user VM */ #endif errno = 0; ATF_REQUIRE_ERRNO(null_errno, mlock(NULL, page) == -1); errno = 0; ATF_REQUIRE_ERRNO(null_errno, mlock((char *)0, page) == -1); errno = 0; ATF_REQUIRE_ERRNO(EINVAL, mlock((char *)-1, page) == -1); errno = 0; ATF_REQUIRE_ERRNO(null_errno, munlock(NULL, page) == -1); errno = 0; ATF_REQUIRE_ERRNO(null_errno, munlock((char *)0, page) == -1); errno = 0; ATF_REQUIRE_ERRNO(EINVAL, munlock((char *)-1, page) == -1); /* * Try to create a pointer to an unmapped page - first after current * brk will likely do. */ invalid_ptr = (void*)(((uintptr_t)sbrk(0)+page) & ~(page-1)); printf("testing with (hopefully) invalid pointer %p\n", invalid_ptr); errno = 0; ATF_REQUIRE_ERRNO(ENOMEM, mlock(invalid_ptr, page) == -1); errno = 0; ATF_REQUIRE_ERRNO(ENOMEM, munlock(invalid_ptr, page) == -1); }
ATF_TC_BODY(fopen_err, tc) { static const char *mode[] = { "x", "xr", "xr", "+r+", "R", "W+", " aXX", "Xr", " r+", "" }; char buf[PATH_MAX + 1]; size_t i; FILE *f; f = fopen(path, "w+"); ATF_REQUIRE(f != NULL); ATF_REQUIRE(fclose(f) == 0); /* * Note that also "invalid" characters * may follow the mode-string whenever * the first character is valid. */ for (i = 0; i < __arraycount(mode); i++) { errno = 0; f = fopen(path, mode[i]); if (f == NULL && errno == EINVAL) continue; if (f != NULL) (void)fclose(f); atf_tc_fail_nonfatal("opened file as '%s'", mode[i]); } (void)unlink(path); (void)memset(buf, 'x', sizeof(buf)); errno = 0; ATF_REQUIRE_ERRNO(EISDIR, fopen("/usr/bin", "w") == NULL); errno = 0; ATF_REQUIRE_ERRNO(ENOENT, fopen("/a/b/c/d/e/f", "r") == NULL); errno = 0; ATF_REQUIRE_ERRNO(ENAMETOOLONG, fopen(buf, "r+") == NULL); }
ATF_TC_BODY(mkfifo_perm, tc) { support(); errno = 0; ATF_REQUIRE_ERRNO(EACCES, mkfifo("/root/fifo", 0600) == -1); ATF_REQUIRE(mkfifo(path, 0600) == 0); /* * For some reason this fails with EFTYPE... */ errno = 0; ATF_REQUIRE_ERRNO(EFTYPE, chmod(path, 1777) == -1); ATF_REQUIRE(unlink(path) == 0); }
ATF_TC_BODY(unlink_fifo, tc) { ATF_REQUIRE(mkfifo(path, 0666) == 0); ATF_REQUIRE(unlink(path) == 0); errno = 0; ATF_REQUIRE_ERRNO(ENOENT, open(path, O_RDONLY) == -1); }
ATF_TC_BODY(setdomainname_perm, tc) { char domain[MAXHOSTNAMELEN]; memset(domain, 0, sizeof(domain)); errno = 0; ATF_REQUIRE_ERRNO(EPERM, setdomainname(domain, sizeof(domain)) == -1); }
ATF_TC_BODY(timer_create_err, tc) { struct sigevent ev; (void)memset(&ev, 0, sizeof(struct sigevent)); errno = 0; ev.sigev_signo = -1; ev.sigev_notify = SIGEV_SIGNAL; ATF_REQUIRE_ERRNO(EINVAL, timer_create(CLOCK_REALTIME, &ev, &t) == -1); errno = 0; ev.sigev_signo = SIGUSR1; ev.sigev_notify = SIGEV_THREAD + 100; ATF_REQUIRE_ERRNO(EINVAL, timer_create(CLOCK_REALTIME, &ev, &t) == -1); }
ATF_TC_BODY(truncate_err, tc) { char buf[PATH_MAX]; errno = 0; ATF_REQUIRE_ERRNO(EFAULT, truncate((void *)-1, 999) == -1); errno = 0; ATF_REQUIRE_ERRNO(EISDIR, truncate("/etc", 999) == -1); errno = 0; ATF_REQUIRE_ERRNO(ENOENT, truncate("/a/b/c/d/e/f/g", 999) == -1); errno = 0; snprintf(buf, sizeof(buf), "%s/truncate_test.root_owned", atf_tc_get_config_var(tc, "srcdir")); ATF_REQUIRE_ERRNO(EACCES, truncate(buf, 999) == -1); }
ATF_TC_BODY(bad_big5_swprintf, tc) { /* XXX implementation detail knowledge (wchar_t encoding) */ wchar_t ibuf[] = { 0xcf10, 0 }; wchar_t obuf[20]; setlocale(LC_CTYPE, "zh_TW.Big5"); ATF_REQUIRE_ERRNO(EILSEQ, swprintf(obuf, sizeof(obuf), L"%ls\n", ibuf) < 0); }
ATF_TC_BODY(unlink_err, tc) { char buf[PATH_MAX + 1]; (void)memset(buf, 'x', sizeof(buf)); errno = 0; #ifdef __FreeBSD__ ATF_REQUIRE_ERRNO(EISDIR, unlink("/") == -1); #else ATF_REQUIRE_ERRNO(EBUSY, unlink("/") == -1); #endif errno = 0; ATF_REQUIRE_ERRNO(ENAMETOOLONG, unlink(buf) == -1); errno = 0; ATF_REQUIRE_ERRNO(ENOENT, unlink("/a/b/c/d/e/f/g/h/i/j/k/l/m") == -1); }
ATF_TC_BODY(listen_err, tc) { static const size_t siz = sizeof(struct sockaddr_in); struct sockaddr_in sina, sinb; int fda, fdb, fdc; (void)memset(&sina, 0, sizeof(struct sockaddr_in)); (void)memset(&sinb, 0, sizeof(struct sockaddr_in)); sina.sin_family = AF_INET; sina.sin_port = htons(31522); sina.sin_addr.s_addr = inet_addr("127.0.0.1"); sinb.sin_family = AF_INET; sinb.sin_port = htons(31522); sinb.sin_addr.s_addr = inet_addr("127.0.0.1"); fda = socket(AF_INET, SOCK_STREAM, 0); fdb = socket(AF_INET, SOCK_STREAM, 0); fdc = open("listen", O_RDWR | O_CREAT, 0600); ATF_REQUIRE(fda >= 0 && fdb >= 0 && fdc >= 0); ATF_REQUIRE_ERRNO(ENOTSOCK, listen(fdc, 1) == -1); (void)close(fdc); (void)unlink(path); ATF_REQUIRE(bind(fda, (struct sockaddr *)&sina, siz) == 0); ATF_REQUIRE(listen(fda, 1) == 0); /* * According to IEEE Std 1003.1-2008: if the socket is * already connected, the call should fail with EINVAL. */ ATF_REQUIRE(connect(fdb, (struct sockaddr *)&sinb, siz) == 0); ATF_REQUIRE_ERRNO(EINVAL, listen(fdb, 1) == -1); (void)close(fda); (void)close(fdb); ATF_REQUIRE_ERRNO(EBADF, connect(fdb, (struct sockaddr *)&sinb, siz) == -1); }