Fix decoding of 3rd argument of getdents/getdents64 syscalls

* dirent.c (SYS_FUNC(getdents)): Always print 3rd syscall argument
as unsigned int.
* dirent64.c (SYS_FUNC(getdents64)): Likewise.
* tests/getdents.c (main): Check it.
* tests/getdents64.c (main): Likewise.
This commit is contained in:
Дмитрий Левин 2016-04-26 22:38:10 +00:00
parent b83bb1cc7a
commit f443fd40cb
4 changed files with 34 additions and 16 deletions

View File

@ -83,9 +83,12 @@ SYS_FUNC(getdents)
tprints(", ");
return 0;
}
const unsigned int count = tcp->u_arg[2];
if (syserror(tcp) || !verbose(tcp)) {
printaddr(tcp->u_arg[1]);
tprintf(", %lu", tcp->u_arg[2]);
tprintf(", %u", count);
return 0;
}
@ -101,7 +104,7 @@ SYS_FUNC(getdents)
buf = malloc(len);
if (!buf || umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
printaddr(tcp->u_arg[1]);
tprintf(", %lu", tcp->u_arg[2]);
tprintf(", %u", count);
free(buf);
return 0;
}
@ -150,7 +153,7 @@ SYS_FUNC(getdents)
tprints("]");
else
tprintf("/* %u entries */", dents);
tprintf(", %lu", tcp->u_arg[2]);
tprintf(", %u", count);
free(buf);
return 0;
}

View File

@ -49,9 +49,12 @@ SYS_FUNC(getdents64)
tprints(", ");
return 0;
}
const unsigned int count = tcp->u_arg[2];
if (syserror(tcp) || !verbose(tcp)) {
printaddr(tcp->u_arg[1]);
tprintf(", %lu", tcp->u_arg[2]);
tprintf(", %u", count);
return 0;
}
@ -67,7 +70,7 @@ SYS_FUNC(getdents64)
buf = malloc(len);
if (!buf || umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
printaddr(tcp->u_arg[1]);
tprintf(", %lu", tcp->u_arg[2]);
tprintf(", %u", count);
free(buf);
return 0;
}
@ -117,7 +120,7 @@ SYS_FUNC(getdents64)
tprints("]");
else
tprintf("/* %u entries */", dents);
tprintf(", %lu", tcp->u_arg[2]);
tprintf(", %u", count);
free(buf);
return 0;
}

View File

@ -96,7 +96,6 @@ int
main(int ac, const char **av)
{
char *dname;
int rc;
assert(ac == 1);
assert(asprintf(&dname, "%s.test.tmp.dir", av[0]) > 0);
@ -106,9 +105,16 @@ main(int ac, const char **av)
assert(!creat(fname, 0600));
assert(!close(0));
assert(!open(".", O_RDONLY | O_DIRECTORY));
while ((rc = syscall(__NR_getdents, 0, buf, sizeof(buf)))) {
unsigned long count = (unsigned long) 0xfacefeeddeadbeef;
long rc = syscall(__NR_getdents, (long) 0xdefacedffffffff, NULL, count);
printf("getdents(-1, NULL, %u) = %ld %s (%m)\n",
(unsigned) count, rc, errno2name());
count = (unsigned long) 0xfacefeed00000000 | sizeof(buf);
while ((rc = syscall(__NR_getdents, 0, buf, count))) {
kernel_dirent *d;
int i;
long i;
if (rc < 0)
perror_msg_and_skip("getdents");
@ -119,9 +125,9 @@ main(int ac, const char **av)
printf(", ");
print_dirent(d);
}
printf("], %zu) = %d\n", sizeof(buf), rc);
printf("], %u) = %ld\n", (unsigned) count, rc);
}
printf("getdents(0, [], %zu) = 0\n", sizeof(buf));
printf("getdents(0, [], %u) = 0\n", (unsigned) count);
puts("+++ exited with 0 +++");
assert(!unlink(fname));
assert(!chdir(".."));

View File

@ -101,7 +101,6 @@ int
main(int ac, const char **av)
{
char *dname;
int rc;
assert(ac == 1);
assert(asprintf(&dname, "%s.test.tmp.dir", av[0]) > 0);
@ -111,9 +110,16 @@ main(int ac, const char **av)
assert(!creat(fname, 0600));
assert(!close(0));
assert(!open(".", O_RDONLY | O_DIRECTORY));
while ((rc = syscall(__NR_getdents64, 0, buf, sizeof(buf)))) {
unsigned long count = (unsigned long) 0xfacefeeddeadbeef;
long rc = syscall(__NR_getdents64, (long) 0xdefacedffffffff, NULL, count);
printf("getdents64(-1, NULL, %u) = %ld %s (%m)\n",
(unsigned) count, rc, errno2name());
count = (unsigned long) 0xfacefeed00000000 | sizeof(buf);
while ((rc = syscall(__NR_getdents64, 0, buf, count))) {
kernel_dirent64 *d;
int i;
long i;
if (rc < 0)
perror_msg_and_skip("getdents64");
@ -124,9 +130,9 @@ main(int ac, const char **av)
printf(", ");
print_dirent(d);
}
printf("], %zu) = %d\n", sizeof(buf), rc);
printf("], %u) = %ld\n", (unsigned) count, rc);
}
printf("getdents64(0, [], %zu) = 0\n", sizeof(buf));
printf("getdents64(0, [], %u) = 0\n", (unsigned) count);
puts("+++ exited with 0 +++");
assert(!unlink(fname));
assert(!chdir(".."));