]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
coregrind/m_debuginfo: don't try to examine zero sized mmapped files
authorMark Wielaard <mark@klomp.org>
Sun, 9 Mar 2025 14:59:29 +0000 (15:59 +0100)
committerMark Wielaard <mark@klomp.org>
Sun, 9 Mar 2025 14:59:29 +0000 (15:59 +0100)
When run on an nfs filesystem memcheck/tests/pointer-trace fails
because it generates warnings "connection to image failed". This is
caused by trying to mmap a deleted file which the nfs file system
represents as a (hidden) regular file. This is normally not a problem
except when that file is empty.

Fix this by not trying to check whether a file is an ELF or MACHO
against an empty (regular) file in di_notify_mmap. An empty file is
never a valid ELF or MACHO file (and cannot be represented as
DiImage).

https://bugs.kde.org/show_bug.cgi?id=501119

NEWS
coregrind/m_debuginfo/debuginfo.c

diff --git a/NEWS b/NEWS
index 0fcbc5d0e2ea40fadba3ca4941758abe9ec762fe..16cfeef2a4f77f33ac82e5dcb13e5f16cb3cba11 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -56,6 +56,7 @@ are not entered into bugzilla tend to get forgotten about or ignored.
 498492  none/tests/amd64/lzcnt64 crashes on FreeBSD compiled with clang
 499183  FreeBSD: differences in avx-vmovq output
 499212  mmap() with MAP_ALIGNED() returns unaligned pointer
+501119  memcheck/tests/pointer-trace fails when run on NFS filesystem
 501194  Fix ML_(check_macho_and_get_rw_loads) so that it is correct for any number of segment commands
 
 
index 612833a997935af39f5ee7cab809f9df6e73d096..15686fc5c46ff8dcf45145a3f0f72a383a48c0f5 100644 (file)
@@ -1206,8 +1206,14 @@ ULong VG_(di_notify_mmap)( Addr a, Bool allow_SkFileV, Int use_fd )
    }
 
    /* Finally, the point of all this stattery: if it's not a regular file,
-      don't try to read debug info from it. */
-   if (! VKI_S_ISREG(statbuf.mode))
+      don't try to read debug info from it. Also if it is a "regular file"
+      but has a zero size then skip it. Having a zero size will definitely
+      fail when trying to create an DiImage and wouldn't be a valid elf or
+      macho file. This can happen when mmapping a deleted file, which
+      would normally fail in the check above, because the stat call will
+      fail.  But if the deleted file is on an NFS file system then a fake
+      (regular) empty file might be returned.  */
+   if (! VKI_S_ISREG(statbuf.mode) || statbuf.size == 0)
       return 0;
 
    /* no uses of statbuf below here. */