From: Bart Van Assche Date: Sun, 25 May 2008 16:25:51 +0000 (+0000) Subject: Bug fixes (not in bugzilla): X-Git-Tag: svn/VALGRIND_3_4_0~558 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=109d59794193ad010e02daa6d7b0414370259bb2;p=thirdparty%2Fvalgrind.git Bug fixes (not in bugzilla): - Make sure that Valgrind does not complain when it tries to read the debug information of a file of size zero when such a file is mmap()'ed into memory. - Make sure the filename is included in the error message that is printed when reading the debug information fails for a file that is mmap()'ed into memory. - Fixed assertion failure that was triggered by supplying an output buffer to VG_(seginfo_sect_kind)() that is smaller than the filename to be copied into that buffer. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@8126 --- diff --git a/coregrind/m_debuginfo/debuginfo.c b/coregrind/m_debuginfo/debuginfo.c index 14ba2b0ddf..c5c7a75864 100644 --- a/coregrind/m_debuginfo/debuginfo.c +++ b/coregrind/m_debuginfo/debuginfo.c @@ -538,9 +538,9 @@ void VG_(di_notify_mmap)( Addr a, Bool allow_SkFileV ) VG_(memset)(buf1k, 0, sizeof(buf1k)); fd = VG_(open)( filename, VKI_O_RDONLY, 0 ); if (fd.isError) { - DebugInfo fake_di; 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"); @@ -550,8 +550,13 @@ void VG_(di_notify_mmap)( Addr a, Bool allow_SkFileV ) nread = VG_(read)( fd.res, buf1k, sizeof(buf1k) ); VG_(close)( fd.res ); - if (nread <= 0) { - ML_(symerr)(NULL, True, "can't read file to inspect ELF header"); + if (nread == 0) + return; + 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; } vg_assert(nread > 0 && nread <= sizeof(buf1k) ); @@ -2325,13 +2330,13 @@ VgSectKind VG_(seginfo_sect_kind)( /*OUT*/UChar* name, SizeT n_name, vg_assert(start_at < fnlen); i = start_at; j = 0; while (True) { - vg_assert(j >= 0 && j+1 < n_name); + vg_assert(j >= 0 && j < n_name); vg_assert(i >= 0 && i <= fnlen); name[j] = di->filename[i]; - name[j+1] = 0; if (di->filename[i] == 0) break; i++; j++; } + vg_assert(i == fnlen); } else { VG_(snprintf)(name, n_name, "%s", "???"); }