]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
_pre_mem_asciiz handlers in both tools: don't segfault if passed an
authorJulian Seward <jseward@acm.org>
Wed, 9 Feb 2011 12:47:23 +0000 (12:47 +0000)
committerJulian Seward <jseward@acm.org>
Wed, 9 Feb 2011 12:47:23 +0000 (12:47 +0000)
obviously invalid address.  Fixes #255009.  Investigation & initial
patch by Philippe Waroquiers (philippe.waroquiers@skynet.be)

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@11533

drd/drd_main.c
helgrind/hg_main.c

index 239f4988c15531d9d0971be7aa3e9bcf103642fe..73984048be5aaa743297612744ab108fe438f93e 100644 (file)
@@ -51,6 +51,7 @@
 #include "pub_tool_replacemalloc.h"
 #include "pub_tool_threadstate.h" // VG_(get_running_tid)()
 #include "pub_tool_tooliface.h"
+#include "pub_tool_aspacemgr.h"   // VG_(am_is_valid_for_client)
 
 
 /* Local variables. */
@@ -257,6 +258,13 @@ static void drd_pre_mem_read_asciiz(const CorePart part,
    const char* p = (void*)a;
    SizeT size = 0;
 
+   // Don't segfault if the string starts in an obviously stupid
+   // place.  Actually we should check the whole string, not just
+   // the start address, but that's too much trouble.  At least
+   // checking the first byte is better than nothing.  See #255009.
+   if (!VG_(am_is_valid_for_client) (a, 1, VKI_PROT_READ))
+      return;
+
    /* Note: the expression '*p' reads client memory and may crash if the */
    /* client provided an invalid pointer !                               */
    while (*p)
index 6af1a733510351fd6f3bb1ee4d107c9b17a5884f..d68cd105514f3f2b060a5206b3c08197c100de67 100644 (file)
@@ -53,6 +53,7 @@
 #include "pub_tool_redir.h"     // sonames for the dynamic linkers
 #include "pub_tool_vki.h"       // VKI_PAGE_SIZE
 #include "pub_tool_libcproc.h"  // VG_(atfork)
+#include "pub_tool_aspacemgr.h" // VG_(am_is_valid_for_client)
 
 #include "hg_basics.h"
 #include "hg_wordset.h"
@@ -1797,7 +1798,12 @@ void evh__pre_mem_read_asciiz ( CorePart part, ThreadId tid,
    if (SHOW_EVENTS >= 1)
       VG_(printf)("evh__pre_mem_asciiz(ctid=%d, \"%s\", %p)\n", 
                   (Int)tid, s, (void*)a );
-   // FIXME: think of a less ugly hack
+   // Don't segfault if the string starts in an obviously stupid
+   // place.  Actually we should check the whole string, not just
+   // the start address, but that's too much trouble.  At least
+   // checking the first byte is better than nothing.  See #255009.
+   if (!VG_(am_is_valid_for_client) (a, 1, VKI_PROT_READ))
+      return;
    len = VG_(strlen)( (Char*) a );
    shadow_mem_cread_range( map_threads_lookup(tid), a, len+1 );
    if (len >= SCE_BIGRANGE_T && (HG_(clo_sanity_flags) & SCE_BIGRANGE))