]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Bug fixes (not in bugzilla):
authorBart Van Assche <bvanassche@acm.org>
Sun, 25 May 2008 16:25:51 +0000 (16:25 +0000)
committerBart Van Assche <bvanassche@acm.org>
Sun, 25 May 2008 16:25:51 +0000 (16:25 +0000)
- 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

coregrind/m_debuginfo/debuginfo.c

index 14ba2b0ddfeea668d43c8fe03ba88b160f024748..c5c7a7586451b283666133b4a4894642202b5356 100644 (file)
@@ -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", "???");
       }