summaryrefslogtreecommitdiff
path: root/helgrind
diff options
context:
space:
mode:
authorsewardj <sewardj@a5019735-40e9-0310-863c-91ae7b9d1cf9>2011-02-09 12:47:23 +0000
committersewardj <sewardj@a5019735-40e9-0310-863c-91ae7b9d1cf9>2011-02-09 12:47:23 +0000
commit234e558d6bcb9d97891fdd41df6a37ad12f26705 (patch)
tree0d21ab19d204a8cd8866ee4b02070713122b02d6 /helgrind
parent9194e93ab737439d653498ee43df4bae7989ad3d (diff)
_pre_mem_asciiz handlers in both tools: don't segfault if passed an
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 a5019735-40e9-0310-863c-91ae7b9d1cf9
Diffstat (limited to 'helgrind')
-rw-r--r--helgrind/hg_main.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/helgrind/hg_main.c b/helgrind/hg_main.c
index 6af1a733..d68cd105 100644
--- a/helgrind/hg_main.c
+++ b/helgrind/hg_main.c
@@ -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))