]> granicus.if.org Git - strace/commitdiff
Don't risk truncating open flags by using mode_t
authorElliott Hughes <enh@google.com>
Wed, 24 Sep 2014 02:09:50 +0000 (19:09 -0700)
committerDmitry V. Levin <ldv@altlinux.org>
Fri, 3 Oct 2014 22:01:37 +0000 (22:01 +0000)
On Android, 32-bit arm and x86 use __kernel_mode_t (an unsigned short)
as their mode_t.  The open(2) flags are actually an int, so high ones
like O_CLOEXEC get truncated if you coerce them to mode_t.

* defs.h (tprint_open_modes, sprint_open_modes): Change argument type
from mode_t to int.
* file.c (tprint_open_modes, sprint_open_modes): Likewise.

Signed-off-by: Elliott Hughes <enh@google.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
defs.h
file.c

diff --git a/defs.h b/defs.h
index cd9817b84d0cac1a5803099dea4d5d6e0f8c10e5..5bfeb6b48212d294e68f1e8a81e74b728b4c1865 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -708,8 +708,8 @@ extern void print_sigset_addr_len(struct tcb *, long, long);
 extern void printsignal(int);
 extern void tprint_iov(struct tcb *, unsigned long, unsigned long, int decode_iov);
 extern void tprint_iov_upto(struct tcb *, unsigned long, unsigned long, int decode_iov, unsigned long);
-extern void tprint_open_modes(mode_t);
-extern const char *sprint_open_modes(mode_t);
+extern void tprint_open_modes(int);
+extern const char *sprint_open_modes(int);
 extern void print_loff_t(struct tcb *, long);
 
 extern const struct_ioctlent *ioctl_lookup(unsigned long);
diff --git a/file.c b/file.c
index c2bf6d3a6464a31b37d96ef886f830befc5d24ec..0ec1d4b6e6b1be43c487e93e2b7b6d5c9d555a9b 100644 (file)
--- a/file.c
+++ b/file.c
@@ -237,7 +237,7 @@ print_dirfd(struct tcb *tcp, int fd)
  * other bits are real flags.
  */
 const char *
-sprint_open_modes(mode_t flags)
+sprint_open_modes(int flags)
 {
        static char outstr[(1 + ARRAY_SIZE(open_mode_flags)) * sizeof("O_LARGEFILE")];
        char *p;
@@ -274,7 +274,7 @@ sprint_open_modes(mode_t flags)
 }
 
 void
-tprint_open_modes(mode_t flags)
+tprint_open_modes(int flags)
 {
        tprints(sprint_open_modes(flags) + sizeof("flags"));
 }