]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
When trying to establish whether or not debuginfo should be read from
authorJulian Seward <jseward@acm.org>
Sat, 8 Nov 2008 15:22:19 +0000 (15:22 +0000)
committerJulian Seward <jseward@acm.org>
Sat, 8 Nov 2008 15:22:19 +0000 (15:22 +0000)
a file, first the mapping permissions _before_ peering at the file's
header, rather than afterwards.  This changes the logic to behave more
like it does in 3.3.x.  Fixes #164669, although really it is all still
rather fragile.  The bug report,
http://bugs.kde.org/show_bug.cgi?id=164669, contains a detailed
explanation.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@8747

coregrind/m_debuginfo/debuginfo.c

index 67498c763fc774dad0f656a5c125b5c095bc2d82..1b1dcf56565e5e9e5027605d2b03c029c4c21d0d 100644 (file)
@@ -664,38 +664,6 @@ ULong VG_(di_notify_mmap)( Addr a, Bool allow_SkFileV )
 
    /* no uses of statbuf below here. */
 
-   /* Peer at the first few bytes of the file, to see if it is an ELF */
-   /* object file. Ignore the file if we do not have read permission. */
-   VG_(memset)(buf1k, 0, sizeof(buf1k));
-   fd = VG_(open)( filename, VKI_O_RDONLY, 0 );
-   if (fd.isError) {
-      if (fd.err != VKI_EACCES)
-      {
-         DebugInfo fake_di;
-         VG_(memset)(&fake_di, 0, sizeof(fake_di));
-         fake_di.filename = filename;
-         ML_(symerr)(&fake_di, True, "can't open file to inspect ELF header");
-      }
-      return 0;
-   }
-   nread = VG_(read)( fd.res, buf1k, sizeof(buf1k) );
-   VG_(close)( fd.res );
-
-   if (nread == 0)
-      return 0;
-   if (nread < 0) {
-      DebugInfo fake_di;
-      VG_(memset)(&fake_di, 0, sizeof(fake_di));
-      fake_di.filename = filename;
-      ML_(symerr)(&fake_di, True, "can't read file to inspect ELF header");
-      return 0;
-   }
-   vg_assert(nread > 0 && nread <= sizeof(buf1k) );
-
-   /* We're only interested in mappings of ELF object files. */
-   if (!ML_(is_elf_object_file)( buf1k, (SizeT)nread ))
-      return 0;
-
    /* Now we have to guess if this is a text-like mapping, a data-like
       mapping, neither or both.  The rules are:
 
@@ -751,6 +719,38 @@ ULong VG_(di_notify_mmap)( Addr a, Bool allow_SkFileV )
    if (!(is_rx_map || is_rw_map))
       return 0;
 
+   /* Peer at the first few bytes of the file, to see if it is an ELF */
+   /* object file. Ignore the file if we do not have read permission. */
+   VG_(memset)(buf1k, 0, sizeof(buf1k));
+   fd = VG_(open)( filename, VKI_O_RDONLY, 0 );
+   if (fd.isError) {
+      if (fd.err != VKI_EACCES)
+      {
+         DebugInfo fake_di;
+         VG_(memset)(&fake_di, 0, sizeof(fake_di));
+         fake_di.filename = filename;
+         ML_(symerr)(&fake_di, True, "can't open file to inspect ELF header");
+      }
+      return 0;
+   }
+   nread = VG_(read)( fd.res, buf1k, sizeof(buf1k) );
+   VG_(close)( fd.res );
+
+   if (nread == 0)
+      return 0;
+   if (nread < 0) {
+      DebugInfo fake_di;
+      VG_(memset)(&fake_di, 0, sizeof(fake_di));
+      fake_di.filename = filename;
+      ML_(symerr)(&fake_di, True, "can't read file to inspect ELF header");
+      return 0;
+   }
+   vg_assert(nread > 0 && nread <= sizeof(buf1k) );
+
+   /* We're only interested in mappings of ELF object files. */
+   if (!ML_(is_elf_object_file)( buf1k, (SizeT)nread ))
+      return 0;
+
    /* See if we have a DebugInfo for this filename.  If not,
       create one. */
    di = find_or_create_DebugInfo_for( filename, NULL/*membername*/ );