tests: check decoding of invalid tv_sec and tv_usec values

* tests/futimesat.c (main): Check decoding of invalid tv_sec and tv_usec
values.
* tests/xetitimer.c (main): Likewise.
* tests/xettimeofday.c (main): Likewise.
* tests/xselect.c (main): Likewise.
* tests/xutimes.c (main): Likewise.
This commit is contained in:
Дмитрий Левин 2017-04-24 00:08:51 +00:00
parent 8b86137d56
commit 89390d356b
5 changed files with 140 additions and 42 deletions

View File

@ -115,6 +115,18 @@ main(void)
printf("futimesat(AT_FDCWD, %s, %p) = %s\n",
qname, tv + 2, errstr);
tv[0].tv_sec = 0xdeadbeefU;
tv[0].tv_usec = 0xfacefeedU;
tv[1].tv_sec = (time_t) 0xcafef00ddeadbeefLL;
tv[1].tv_usec = (long) 0xbadc0dedfacefeedLL;
k_futimesat(kfdcwd, kfname, (uintptr_t) tv);
printf("futimesat(AT_FDCWD, %s, [", qname);
print_tv(&tv[0]);
printf(", ");
print_tv(&tv[1]);
printf("]) = %s\n", errstr);
tv[0].tv_sec = 1492356708;
tv[0].tv_usec = 567891234;
tv[1].tv_sec = 1492357086;

View File

@ -164,6 +164,21 @@ main(void)
(unsigned long long) ill_old, sprintrc(rc));
}
p_new->it_interval.tv_sec = 0xdeadbeefU;
p_new->it_interval.tv_usec = 0xfacefeedU;
p_new->it_value.tv_sec = (time_t) 0xcafef00ddeadbeefLL;
p_new->it_value.tv_usec = (long) 0xbadc0dedfacefeedLL;
rc = setitimer(ITIMER_REAL, p_new, p_old);
printf("setitimer(ITIMER_REAL"
", {it_interval={tv_sec=%lld, tv_usec=%llu}"
", it_value={tv_sec=%lld, tv_usec=%llu}}, %p) = %s\n",
(long long) p_new->it_interval.tv_sec,
zero_extend_signed_to_ull(p_new->it_interval.tv_usec),
(long long) p_new->it_value.tv_sec,
zero_extend_signed_to_ull(p_new->it_value.tv_usec),
p_old, sprintrc(rc));
puts("+++ exited with 0 +++");
return 0;
}

View File

@ -36,39 +36,49 @@
int
main(void)
{
struct {
struct timeval tv;
uint32_t pad0[2];
struct timezone tz;
uint32_t pad1[2];
} t = {
.pad0 = { 0xdeadbeef, 0xbadc0ded },
.pad1 = { 0xdeadbeef, 0xbadc0ded }
};
TAIL_ALLOC_OBJECT_CONST_PTR(struct timeval, tv);
TAIL_ALLOC_OBJECT_CONST_PTR(struct timezone, tz);
if (syscall(__NR_gettimeofday, &t.tv, NULL))
if (syscall(__NR_gettimeofday, tv, NULL))
perror_msg_and_skip("gettimeofday");
printf("gettimeofday({tv_sec=%lld, tv_usec=%llu}, NULL) = 0\n",
(long long) t.tv.tv_sec,
zero_extend_signed_to_ull(t.tv.tv_usec));
(long long) tv->tv_sec,
zero_extend_signed_to_ull(tv->tv_usec));
if (syscall(__NR_gettimeofday, &t.tv, &t.tz))
if (syscall(__NR_gettimeofday, tv, tz))
perror_msg_and_skip("gettimeofday");
printf("gettimeofday({tv_sec=%lld, tv_usec=%llu}"
", {tz_minuteswest=%d, tz_dsttime=%d}) = 0\n",
(long long) t.tv.tv_sec,
zero_extend_signed_to_ull(t.tv.tv_usec),
t.tz.tz_minuteswest, t.tz.tz_dsttime);
(long long) tv->tv_sec,
zero_extend_signed_to_ull(tv->tv_usec),
tz->tz_minuteswest, tz->tz_dsttime);
t.tv.tv_sec = -1;
t.tv.tv_usec = 1000000000;
assert(syscall(__NR_settimeofday, &t.tv, &t.tz) == -1);
tv->tv_sec = -1;
tv->tv_usec = 1000000;
assert(syscall(__NR_settimeofday, tv, tz) == -1);
printf("settimeofday({tv_sec=%lld, tv_usec=%llu}"
", {tz_minuteswest=%d, tz_dsttime=%d})"
" = -1 EINVAL (%m)\n",
(long long) t.tv.tv_sec,
zero_extend_signed_to_ull(t.tv.tv_usec),
t.tz.tz_minuteswest, t.tz.tz_dsttime);
", {tz_minuteswest=%d, tz_dsttime=%d}) = -1 EINVAL (%m)\n",
(long long) tv->tv_sec,
zero_extend_signed_to_ull(tv->tv_usec),
tz->tz_minuteswest, tz->tz_dsttime);
tv->tv_sec = 0xdeadbeefU;
tv->tv_usec = 0xfacefeedU;
assert(syscall(__NR_settimeofday, tv, tz) == -1);
printf("settimeofday({tv_sec=%lld, tv_usec=%llu}"
", {tz_minuteswest=%d, tz_dsttime=%d}) = -1 EINVAL (%m)\n",
(long long) tv->tv_sec,
zero_extend_signed_to_ull(tv->tv_usec),
tz->tz_minuteswest, tz->tz_dsttime);
tv->tv_sec = (time_t) 0xcafef00ddeadbeefLL;
tv->tv_usec = (long) 0xbadc0dedfacefeedLL;
assert(syscall(__NR_settimeofday, tv, tz) == -1);
printf("settimeofday({tv_sec=%lld, tv_usec=%llu}"
", {tz_minuteswest=%d, tz_dsttime=%d}) = -1 EINVAL (%m)\n",
(long long) tv->tv_sec,
zero_extend_signed_to_ull(tv->tv_usec),
tz->tz_minuteswest, tz->tz_dsttime);
puts("+++ exited with 0 +++");
return 0;

View File

@ -31,6 +31,7 @@
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/select.h>
@ -38,14 +39,10 @@ static fd_set set[0x1000000 / sizeof(fd_set)];
int main(void)
{
TAIL_ALLOC_OBJECT_CONST_PTR(struct timeval, tv);
struct timeval tv_in;
int fds[2];
struct {
struct timeval tv;
int pad[2];
} tm_in = {
.tv = { .tv_sec = 0xc0de1, .tv_usec = 0xc0de2 },
.pad = { 0xdeadbeef, 0xbadc0ded }
}, tm = tm_in;
long rc;
if (pipe(fds))
perror_msg_and_fail("pipe");
@ -56,7 +53,7 @@ int main(void)
FD_ZERO(set);
FD_SET(fds[0], set);
FD_SET(fds[1], set);
int rc = syscall(TEST_SYSCALL_NR, fds[1] + 1, set, set, set, NULL);
rc = syscall(TEST_SYSCALL_NR, fds[1] + 1, set, set, set, NULL);
if (rc < 0)
perror_msg_and_skip(TEST_SYSCALL_STR);
assert(rc == 1);
@ -64,6 +61,55 @@ int main(void)
TEST_SYSCALL_STR, fds[1] + 1, fds[0], fds[1],
fds[0], fds[1], fds[0], fds[1]);
/*
* Odd timeout.
*/
FD_SET(fds[0], set);
FD_SET(fds[1], set);
tv->tv_sec = 0xdeadbeefU;
tv->tv_usec = 0xfacefeedU;
memcpy(&tv_in, tv, sizeof(tv_in));
rc = syscall(TEST_SYSCALL_NR, fds[1] + 1, set, set, set, tv);
if (rc < 0) {
printf("%s(%d, [%d %d], [%d %d], [%d %d]"
", {tv_sec=%lld, tv_usec=%llu}) = %s\n",
TEST_SYSCALL_STR, fds[1] + 1, fds[0], fds[1],
fds[0], fds[1], fds[0], fds[1], (long long) tv->tv_sec,
zero_extend_signed_to_ull(tv->tv_usec), sprintrc(rc));
} else {
printf("%s(%d, [%d %d], [%d %d], [%d %d]"
", {tv_sec=%lld, tv_usec=%llu}) = %ld"
" (left {tv_sec=%lld, tv_usec=%llu})\n",
TEST_SYSCALL_STR, fds[1] + 1, fds[0], fds[1],
fds[0], fds[1], fds[0], fds[1], (long long) tv_in.tv_sec,
zero_extend_signed_to_ull(tv_in.tv_usec),
rc, (long long) tv->tv_sec,
zero_extend_signed_to_ull(tv->tv_usec));
}
FD_SET(fds[0], set);
FD_SET(fds[1], set);
tv->tv_sec = (time_t) 0xcafef00ddeadbeefLL;
tv->tv_usec = (long) 0xbadc0dedfacefeedLL;
memcpy(&tv_in, tv, sizeof(tv_in));
rc = syscall(TEST_SYSCALL_NR, fds[1] + 1, set, set, set, tv);
if (rc < 0) {
printf("%s(%d, [%d %d], [%d %d], [%d %d]"
", {tv_sec=%lld, tv_usec=%llu}) = %s\n",
TEST_SYSCALL_STR, fds[1] + 1, fds[0], fds[1],
fds[0], fds[1], fds[0], fds[1], (long long) tv->tv_sec,
zero_extend_signed_to_ull(tv->tv_usec), sprintrc(rc));
} else {
printf("%s(%d, [%d %d], [%d %d], [%d %d]"
", {tv_sec=%lld, tv_usec=%llu}) = %ld"
" (left {tv_sec=%lld, tv_usec=%llu})\n",
TEST_SYSCALL_STR, fds[1] + 1, fds[0], fds[1],
fds[0], fds[1], fds[0], fds[1], (long long) tv_in.tv_sec,
zero_extend_signed_to_ull(tv_in.tv_usec),
rc, (long long) tv->tv_sec,
zero_extend_signed_to_ull(tv->tv_usec));
}
/*
* Another simple one, with a timeout.
*/
@ -71,15 +117,18 @@ int main(void)
FD_SET(2, set);
FD_SET(fds[0], set);
FD_SET(fds[1], set);
assert(syscall(TEST_SYSCALL_NR, fds[1] + 1, NULL, set, NULL, &tm.tv) == 3);
tv->tv_sec = 0xc0de1;
tv->tv_usec = 0xc0de2;
memcpy(&tv_in, tv, sizeof(tv_in));
assert(syscall(TEST_SYSCALL_NR, fds[1] + 1, NULL, set, NULL, tv) == 3);
printf("%s(%d, NULL, [1 2 %d %d], NULL, {tv_sec=%lld, tv_usec=%llu})"
" = 3 (out [1 2 %d], left {tv_sec=%lld, tv_usec=%llu})\n",
TEST_SYSCALL_STR, fds[1] + 1, fds[0], fds[1],
(long long) tm_in.tv.tv_sec,
zero_extend_signed_to_ull(tm_in.tv.tv_usec),
(long long) tv_in.tv_sec,
zero_extend_signed_to_ull(tv_in.tv_usec),
fds[1],
(long long) tm.tv.tv_sec,
zero_extend_signed_to_ull(tm.tv.tv_usec));
(long long) tv->tv_sec,
zero_extend_signed_to_ull(tv->tv_usec));
/*
* Now the crash case that trinity found, negative nfds
@ -96,9 +145,9 @@ int main(void)
*/
FD_ZERO(set);
FD_SET(fds[0],set);
tm.tv.tv_sec = 0;
tm.tv.tv_usec = 123;
assert(syscall(TEST_SYSCALL_NR, FD_SETSIZE + 1, set, set + 1, NULL, &tm.tv) == 0);
tv->tv_sec = 0;
tv->tv_usec = 123;
assert(syscall(TEST_SYSCALL_NR, FD_SETSIZE + 1, set, set + 1, NULL, tv) == 0);
printf("%s(%d, [%d], [], NULL, {tv_sec=0, tv_usec=123}) = 0 (Timeout)\n",
TEST_SYSCALL_STR, FD_SETSIZE + 1, fds[0]);

View File

@ -104,10 +104,22 @@ main(void)
printf("%s(%s, %p) = %s\n", TEST_SYSCALL_STR,
qname, tv + 2, errstr);
tv[0].tv_sec = 0xdeadbeefU;
tv[0].tv_usec = 0xfacefeedU;
tv[1].tv_sec = (time_t) 0xcafef00ddeadbeefLL;
tv[1].tv_usec = (long) 0xbadc0dedfacefeedLL;
k_utimes(kfname, (uintptr_t) tv);
printf("%s(%s, [", TEST_SYSCALL_STR, qname);
print_tv(&tv[0]);
printf(", ");
print_tv(&tv[1]);
printf("]) = %s\n", errstr);
tv[0].tv_sec = 1492358607;
tv[0].tv_usec = 345678912;
tv[0].tv_usec = 1000000;
tv[1].tv_sec = 1492356078;
tv[1].tv_usec = 456789023;
tv[1].tv_usec = 1000001;
k_utimes(kfname, (uintptr_t) tv);
printf("%s(%s, [", TEST_SYSCALL_STR, qname);