Jakub Jelinek e6fdd7
Testcase:
Jakub Jelinek e6fdd7
#define _GNU_SOURCE
Jakub Jelinek e6fdd7
#include <fcntl.h>
Jakub Jelinek e6fdd7
#include <unistd.h>
Jakub Jelinek e6fdd7
Jakub Jelinek e6fdd7
int
Jakub Jelinek e6fdd7
main (void)
Jakub Jelinek e6fdd7
{
Jakub Jelinek e6fdd7
  int dfd = open ("/tmp", O_RDONLY);
Jakub Jelinek e6fdd7
  int fd1 = openat (dfd, "abc", O_RDONLY);
Jakub Jelinek e6fdd7
  int fd2 = openat (0x12345678, "/tmp/abc", O_RDONLY);
Jakub Jelinek e6fdd7
  int fd3 = openat (AT_FDCWD, "abc", O_RDONLY);
Jakub Jelinek e6fdd7
  /* This is the only one that should warn.  */
Jakub Jelinek e6fdd7
  int fd4 = openat (0x12345678, "abc", O_RDONLY);
Jakub Jelinek e6fdd7
  return 0;
Jakub Jelinek e6fdd7
}
Jakub Jelinek e6fdd7
Jakub Jelinek e6fdd7
--- valgrind-3.2.3/include/vki-linux.h.jj	2006-08-28 15:38:37.000000000 +0200
Jakub Jelinek e6fdd7
+++ valgrind-3.2.3/include/vki-linux.h	2006-09-26 18:29:00.000000000 +0200
Jakub Jelinek e6fdd7
@@ -1223,6 +1223,8 @@ struct vki_dirent {
Jakub Jelinek e6fdd7
 
Jakub Jelinek e6fdd7
 #define VKI_F_NOTIFY	(VKI_F_LINUX_SPECIFIC_BASE+2)
Jakub Jelinek e6fdd7
 
Jakub Jelinek e6fdd7
+#define VKI_AT_FDCWD	-100
Jakub Jelinek e6fdd7
+
Jakub Jelinek e6fdd7
 //----------------------------------------------------------------------
Jakub Jelinek e6fdd7
 // From linux-2.6.8.1/include/linux/sysctl.h
Jakub Jelinek e6fdd7
 //----------------------------------------------------------------------
Jakub Jelinek e6fdd7
--- valgrind-3.2.3/coregrind/m_syswrap/syswrap-linux.c.jj	2006-08-28 15:38:57.000000000 +0200
Jakub Jelinek e6fdd7
+++ valgrind-3.2.3/coregrind/m_syswrap/syswrap-linux.c	2006-09-26 18:42:04.000000000 +0200
Jakub Jelinek e6fdd7
@@ -2350,10 +2350,15 @@ PRE(sys_openat)
Jakub Jelinek e6fdd7
                     int, dfd, const char *, filename, int, flags);
Jakub Jelinek e6fdd7
    }
Jakub Jelinek e6fdd7
 
Jakub Jelinek e6fdd7
-   if (!ML_(fd_allowed)(ARG1, "openat", tid, False))
Jakub Jelinek e6fdd7
+   PRE_MEM_RASCIIZ( "openat(filename)", ARG2 );
Jakub Jelinek e6fdd7
+
Jakub Jelinek e6fdd7
+   /* For absolute filenames, dfd is ignored.  If dfd is AT_FDCWD,
Jakub Jelinek e6fdd7
+      filename is relative to cwd.  */   
Jakub Jelinek e6fdd7
+   if (ML_(safe_to_deref)( (void*)ARG2, 1 )
Jakub Jelinek e6fdd7
+       && *(Char *)ARG2 != '/'
Jakub Jelinek e6fdd7
+       && ARG1 != VKI_AT_FDCWD
Jakub Jelinek e6fdd7
+       && !ML_(fd_allowed)(ARG1, "openat", tid, False))
Jakub Jelinek e6fdd7
       SET_STATUS_Failure( VKI_EBADF );
Jakub Jelinek e6fdd7
-   else
Jakub Jelinek e6fdd7
-      PRE_MEM_RASCIIZ( "openat(filename)", ARG2 );
Jakub Jelinek e6fdd7
 
Jakub Jelinek e6fdd7
    /* Handle the case where the open is of /proc/self/cmdline or
Jakub Jelinek e6fdd7
       /proc/<pid>/cmdline, and just give it a copy of the fd for the