2007-02-13 12:33:04 +00:00
|
|
|
Testcase:
|
|
|
|
#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);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-09-20 14:48:45 +00:00
|
|
|
--- valgrind-3.8.1/coregrind/m_syswrap/syswrap-linux.c.jj 2007-12-11 00:18:43.000000000 +0100
|
|
|
|
+++ valgrind-3.8.1/coregrind/m_syswrap/syswrap-linux.c 2008-03-03 11:35:15.000000000 +0100
|
2012-08-07 22:24:14 +00:00
|
|
|
@@ -3308,10 +3308,15 @@ PRE(sys_openat)
|
2007-02-13 12:33:04 +00:00
|
|
|
int, dfd, const char *, filename, int, flags);
|
|
|
|
}
|
|
|
|
|
2008-03-03 12:58:38 +00:00
|
|
|
- if (ARG1 != VKI_AT_FDCWD && !ML_(fd_allowed)(ARG1, "openat", tid, False))
|
2007-02-13 12:33:04 +00:00
|
|
|
+ PRE_MEM_RASCIIZ( "openat(filename)", ARG2 );
|
|
|
|
+
|
|
|
|
+ /* For absolute filenames, dfd is ignored. If dfd is AT_FDCWD,
|
2008-03-03 12:58:38 +00:00
|
|
|
+ filename is relative to cwd. */
|
2007-02-13 12:33:04 +00:00
|
|
|
+ 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
|