From: Julian Seward Date: Sat, 8 Nov 2008 15:22:19 +0000 (+0000) Subject: When trying to establish whether or not debuginfo should be read from X-Git-Tag: svn/VALGRIND_3_4_0~147 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cf588ba40dc1d5c5449f4c3203c7ad1b7b15bc1f;p=thirdparty%2Fvalgrind.git When trying to establish whether or not debuginfo should be read from 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 --- diff --git a/coregrind/m_debuginfo/debuginfo.c b/coregrind/m_debuginfo/debuginfo.c index 67498c763f..1b1dcf5656 100644 --- a/coregrind/m_debuginfo/debuginfo.c +++ b/coregrind/m_debuginfo/debuginfo.c @@ -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*/ );