]> granicus.if.org Git - strace/commitdiff
Fix dumping of io syscalls when descriptor argument has unused bits set
authorDmitry V. Levin <ldv@altlinux.org>
Tue, 29 Nov 2016 22:56:49 +0000 (22:56 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Tue, 29 Nov 2016 22:56:49 +0000 (22:56 +0000)
* syscall.c (dumpio): Explicitly cast the first argument of syscall
to "int", the same way as the kernel does.
* tests/read-write.c: Include <asm/unistd.h> and "kernel_types.h".
(k_read, k_write): New functions.
(test_dump, main): Use them.

syscall.c
tests/read-write.c

index ae145b45255fbe9415d2ab46769b0dde6087059f..325a7eb100272c8d2b9c99d623a299c01b6b1a46 100644 (file)
--- a/syscall.c
+++ b/syscall.c
@@ -895,16 +895,18 @@ decode_mips_subcall(struct tcb *tcp)
 static void
 dumpio(struct tcb *tcp)
 {
-       int sen;
-
        if (syserror(tcp))
                return;
-       if ((unsigned long) tcp->u_arg[0] >= num_quals)
+
+       int fd = tcp->u_arg[0];
+       if (fd < 0 || (unsigned int) fd >= num_quals)
                return;
-       sen = tcp->s_ent->sen;
+
+       int sen = tcp->s_ent->sen;
        if (SEN_printargs == sen)
                return;
-       if (qual_flags[tcp->u_arg[0]] & QUAL_READ) {
+
+       if (qual_flags[fd] & QUAL_READ) {
                switch (sen) {
                case SEN_read:
                case SEN_pread:
@@ -927,7 +929,7 @@ dumpio(struct tcb *tcp)
                        return;
                }
        }
-       if (qual_flags[tcp->u_arg[0]] & QUAL_WRITE) {
+       if (qual_flags[fd] & QUAL_WRITE) {
                switch (sen) {
                case SEN_write:
                case SEN_pwrite:
index 4d1e7302c7b9f197fa0e37de720cecae27ed3aee..0e3ff66afbb911ea898285bf3a981129cc6b7581 100644 (file)
@@ -33,6 +33,8 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <asm/unistd.h>
+#include "kernel_types.h"
 
 static void
 dump_str(const char *str, const unsigned int len)
@@ -77,6 +79,20 @@ print_hex(const char *str, const unsigned int len)
        }
 }
 
+static long
+k_read(unsigned int fd, void *buf, size_t count)
+{
+       kernel_ulong_t kfd = (kernel_ulong_t) 0xfacefeed00000000ULL | fd;
+       return syscall(__NR_read, kfd, buf, count);
+}
+
+static long
+k_write(unsigned int fd, const void *buf, size_t count)
+{
+       kernel_ulong_t kfd = (kernel_ulong_t) 0xfacefeed00000000ULL | fd;
+       return syscall(__NR_write, kfd, buf, count);
+}
+
 static void
 test_dump(const unsigned int len)
 {
@@ -89,7 +105,7 @@ test_dump(const unsigned int len)
                buf = tail_alloc(len);
        }
 
-       long rc = read(0, buf, len);
+       long rc = k_read(0, buf, len);
        if (rc != (int) len)
                perror_msg_and_fail("read: expected %d, returned %ld",
                                    len, rc);
@@ -103,7 +119,7 @@ test_dump(const unsigned int len)
        for (i = 0; i < len; ++i)
                buf[i] = i;
 
-       rc = write(1, buf, len);
+       rc = k_write(1, buf, len);
        if (rc != (int) len)
                perror_msg_and_fail("write: expected %d, returned %ld",
                                    len, rc);
@@ -147,18 +163,18 @@ main(void)
 
        long rc;
 
-       rc = write(1, w, 0);
+       rc = k_write(1, w, 0);
        if (rc)
                perror_msg_and_fail("write: expected 0, returned %ld", rc);
        tprintf("write(1, \"\", 0) = 0\n");
 
-       rc = write(1, efault, 1);
+       rc = k_write(1, efault, 1);
        if (rc != -1)
                perror_msg_and_fail("write: expected -1 EFAULT"
                                    ", returned %ld", rc);
        tprintf("write(1, %p, 1) = -1 EFAULT (%m)\n", efault);
 
-       rc = write(1, w, w_len);
+       rc = k_write(1, w, w_len);
        if (rc != (int) w_len)
                perror_msg_and_fail("write: expected %u, returned %ld",
                                    w_len, rc);
@@ -167,17 +183,17 @@ main(void)
                w_c, w_len, rc, w_d, w_c);
        close(1);
 
-       rc = read(0, r0, 0);
+       rc = k_read(0, r0, 0);
        if (rc)
                perror_msg_and_fail("read: expected 0, returned %ld", rc);
        tprintf("read(0, \"\", 0) = 0\n");
 
-       rc = read(0, efault, 1);
+       rc = k_read(0, efault, 1);
        if (rc != -1)
                perror_msg_and_fail("read: expected -1, returned %ld", rc);
        tprintf("read(0, %p, 1) = -1 EFAULT (%m)\n", efault);
 
-       rc = read(0, r0, r0_len);
+       rc = k_read(0, r0, r0_len);
        if (rc != (int) r0_len)
                perror_msg_and_fail("read: expected %u, returned %ld",
                                    r0_len, rc);
@@ -185,7 +201,7 @@ main(void)
                " | 00000 %-49s  %-16s |\n",
                r0_c, r0_len, rc, r0_d, r0_c);
 
-       rc = read(0, r1, w_len);
+       rc = k_read(0, r1, w_len);
        if (rc != (int) r1_len)
                perror_msg_and_fail("read: expected %u, returned %ld",
                                    r1_len, rc);