|
From: <sv...@va...> - 2012-12-06 16:05:30
|
sewardj 2012-12-06 16:05:18 +0000 (Thu, 06 Dec 2012)
New Revision: 13159
Log:
For sys-openat the dirfd argument should be ignored when the pathname
is absolute. Fixes #307103. (Mark Wielaard, mj...@re...)
Added files:
trunk/memcheck/tests/linux/sys-openat.c
trunk/memcheck/tests/linux/sys-openat.stderr.exp
trunk/memcheck/tests/linux/sys-openat.stdout.exp
trunk/memcheck/tests/linux/sys-openat.vgtest
Modified files:
trunk/coregrind/m_syswrap/syswrap-linux.c
trunk/memcheck/tests/linux/Makefile.am
Added: trunk/memcheck/tests/linux/sys-openat.stdout.exp (+0 -0)
===================================================================
Added: trunk/memcheck/tests/linux/sys-openat.vgtest (+1 -0)
===================================================================
--- trunk/memcheck/tests/linux/sys-openat.vgtest 2012-12-06 05:04:35 +00:00 (rev 13158)
+++ trunk/memcheck/tests/linux/sys-openat.vgtest 2012-12-06 16:05:18 +00:00 (rev 13159)
@@ -0,0 +1 @@
+prog: sys-openat
Added: trunk/memcheck/tests/linux/sys-openat.stderr.exp (+11 -0)
===================================================================
--- trunk/memcheck/tests/linux/sys-openat.stderr.exp 2012-12-06 05:04:35 +00:00 (rev 13158)
+++ trunk/memcheck/tests/linux/sys-openat.stderr.exp 2012-12-06 16:05:18 +00:00 (rev 13159)
@@ -0,0 +1,11 @@
+
+Warning: invalid file descriptor 305419896 in syscall openat()
+
+HEAP SUMMARY:
+ in use at exit: 0 bytes in 0 blocks
+ total heap usage: 0 allocs, 0 frees, 0 bytes allocated
+
+For a detailed leak analysis, rerun with: --leak-check=full
+
+For counts of detected and suppressed errors, rerun with: -v
+ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
Modified: trunk/memcheck/tests/linux/Makefile.am (+2 -0)
===================================================================
--- trunk/memcheck/tests/linux/Makefile.am 2012-12-06 05:04:35 +00:00 (rev 13158)
+++ trunk/memcheck/tests/linux/Makefile.am 2012-12-06 16:05:18 +00:00 (rev 13159)
@@ -14,6 +14,7 @@
stack_switch.stderr.exp stack_switch.vgtest \
syscalls-2007.vgtest syscalls-2007.stderr.exp \
syslog-syscall.vgtest syslog-syscall.stderr.exp \
+ sys-openat.vgtest sys-openat.stderr.exp sys-openat.stdout.exp \
timerfd-syscall.vgtest timerfd-syscall.stderr.exp \
with-space.stderr.exp with-space.stdout.exp with-space.vgtest \
proc-auxv.vgtest proc-auxv.stderr.exp getregset.vgtest \
@@ -30,6 +31,7 @@
stack_switch \
syscalls-2007 \
syslog-syscall \
+ sys-openat \
timerfd-syscall \
proc-auxv
Modified: trunk/coregrind/m_syswrap/syswrap-linux.c (+8 -3)
===================================================================
--- trunk/coregrind/m_syswrap/syswrap-linux.c 2012-12-06 05:04:35 +00:00 (rev 13158)
+++ trunk/coregrind/m_syswrap/syswrap-linux.c 2012-12-06 16:05:18 +00:00 (rev 13159)
@@ -3794,10 +3794,15 @@
int, dfd, const char *, filename, int, flags);
}
- if (ARG1 != VKI_AT_FDCWD && !ML_(fd_allowed)(ARG1, "openat", tid, False))
+ PRE_MEM_RASCIIZ( "openat(filename)", ARG2 );
+
+ /* For absolute filenames, dfd is ignored. If dfd is AT_FDCWD,
+ filename is relative to cwd. */
+ if (ML_(safe_to_deref)( (void*)ARG2, 1 )
+ && *(Char *)ARG2 != '/'
+ && ARG1 != VKI_AT_FDCWD
+ && !ML_(fd_allowed)(ARG1, "openat", tid, False))
SET_STATUS_Failure( VKI_EBADF );
- else
- PRE_MEM_RASCIIZ( "openat(filename)", ARG2 );
/* Handle the case where the open is of /proc/self/cmdline or
/proc/<pid>/cmdline, and just give it a copy of the fd for the
Added: trunk/memcheck/tests/linux/sys-openat.c (+19 -0)
===================================================================
--- trunk/memcheck/tests/linux/sys-openat.c 2012-12-06 05:04:35 +00:00 (rev 13158)
+++ trunk/memcheck/tests/linux/sys-openat.c 2012-12-06 16:05:18 +00:00 (rev 13159)
@@ -0,0 +1,19 @@
+
+/* The bug that gave rise to this is
+ https://bugs.kde.org/show_bug.cgi?id=307103
+*/
+
+#define _GNU_SOURCE
+#include <fcntl.h>
+#include <unistd.h>
+int main (void)
+{
+ int dfd = open ("/tmp", O_RDONLY);
+ int fd1 = openat (dfd, "abc", O_RDONLY);
+ /* This is fine, absolute path. */
+ int fd2 = openat (0x12345678, "/tmp/abc", O_RDONLY);
+ int fd3 = openat (AT_FDCWD, "abc", O_RDONLY);
+ /* This is the only one that should warn. */
+ int fd4 = openat (0x12345678, "abc", O_RDONLY);
+ return 0;
+}
|