e6fdd7
Testcase:
e6fdd7
#define _GNU_SOURCE
e6fdd7
#include <fcntl.h>
e6fdd7
#include <unistd.h>
e6fdd7
e6fdd7
int
e6fdd7
main (void)
e6fdd7
{
e6fdd7
  int dfd = open ("/tmp", O_RDONLY);
e6fdd7
  int fd1 = openat (dfd, "abc", O_RDONLY);
e6fdd7
  int fd2 = openat (0x12345678, "/tmp/abc", O_RDONLY);
e6fdd7
  int fd3 = openat (AT_FDCWD, "abc", O_RDONLY);
e6fdd7
  /* This is the only one that should warn.  */
e6fdd7
  int fd4 = openat (0x12345678, "abc", O_RDONLY);
e6fdd7
  return 0;
e6fdd7
}
e6fdd7
Mark Wielaard f4ddfb
--- valgrind-3.8.0/coregrind/m_syswrap/syswrap-linux.c.jj	2007-12-11 00:18:43.000000000 +0100
Mark Wielaard f4ddfb
+++ valgrind-3.8.0/coregrind/m_syswrap/syswrap-linux.c	2008-03-03 11:35:15.000000000 +0100
Mark Wielaard f4ddfb
@@ -3308,10 +3308,15 @@ PRE(sys_openat)
e6fdd7
                     int, dfd, const char *, filename, int, flags);
e6fdd7
    }
e6fdd7
 
888c61
-   if (ARG1 != VKI_AT_FDCWD && !ML_(fd_allowed)(ARG1, "openat", tid, False))
e6fdd7
+   PRE_MEM_RASCIIZ( "openat(filename)", ARG2 );
e6fdd7
+
e6fdd7
+   /* For absolute filenames, dfd is ignored.  If dfd is AT_FDCWD,
888c61
+      filename is relative to cwd.  */
e6fdd7
+   if (ML_(safe_to_deref)( (void*)ARG2, 1 )
e6fdd7
+       && *(Char *)ARG2 != '/'
e6fdd7
+       && ARG1 != VKI_AT_FDCWD
e6fdd7
+       && !ML_(fd_allowed)(ARG1, "openat", tid, False))
e6fdd7
       SET_STATUS_Failure( VKI_EBADF );
e6fdd7
-   else
e6fdd7
-      PRE_MEM_RASCIIZ( "openat(filename)", ARG2 );
e6fdd7
 
e6fdd7
    /* Handle the case where the open is of /proc/self/cmdline or
e6fdd7
       /proc/<pid>/cmdline, and just give it a copy of the fd for the