]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Ensure memory acquired from sys_brk() really is zeroed. Fixes #121893.
authorJulian Seward <jseward@acm.org>
Tue, 14 Feb 2006 11:37:41 +0000 (11:37 +0000)
committerJulian Seward <jseward@acm.org>
Tue, 14 Feb 2006 11:37:41 +0000 (11:37 +0000)
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@5647

coregrind/m_syswrap/syswrap-generic.c
docs/internals/3_1_BUGSTATUS.txt

index c687eb4bd440dc8dbde66036cd64ca9126305e3d..5fffa034548df12c2c293144a27fe943dbdf91a1 100644 (file)
@@ -947,6 +947,23 @@ static Addr do_brk ( Addr newbrk )
       if (seg && seg->hasT)
          VG_(discard_translations)( newbrk, VG_(brk_limit) - newbrk, 
                                     "do_brk(shrink)" );
+      /* Since we're being lazy and not unmapping pages, we have to
+         zero out the area, so that if the area later comes back into
+         circulation, it will be filled with zeroes, as if it really
+         had been unmapped and later remapped.  Be a bit paranoid and
+         try hard to ensure we're not going to segfault by doing the
+         write - check both ends of the range are in the same segment
+         and that segment is writable. */
+      if (seg) {
+         /* pre: newbrk < VG_(brk_limit) 
+              => newbrk <= VG_(brk_limit)-1 */
+         NSegment* seg2;
+         vg_assert(newbrk < VG_(brk_limit));
+         seg2 = VG_(am_find_nsegment)( VG_(brk_limit)-1 );
+         if (seg2 && seg == seg2 && seg->hasW)
+            VG_(memset)( (void*)newbrk, 0, VG_(brk_limit) - newbrk );
+      }
+
       VG_(brk_limit) = newbrk;
       return newbrk;
    }
index d5dd6ad2de617a9d58ea388ab032d1567fd7efba..dca1bac84a4e452c9b1026b4ac17fc31cc3ef190 100644 (file)
@@ -53,7 +53,7 @@ v5593     pending   120658   Pass -Wdeclaration-after-statement to VEX build
 120277 unimplemented PPC floating point instructions: fres, fctid,
        fctidz, frsqrte
 
-
+v5647     pending   121893   calloc does not always zero memory
 
 
 don't forget: