summaryrefslogtreecommitdiff
path: root/pcretest.c
diff options
context:
space:
mode:
authorchpe <chpe@2f5784b3-3f2a-0410-8824-cb99058d5e15>2012-10-21 16:53:57 +0000
committerchpe <chpe@2f5784b3-3f2a-0410-8824-cb99058d5e15>2012-10-21 16:53:57 +0000
commit7777b1557740c6b881bc22d5cd450525a372521d (patch)
treeba20b8cf2dd9eaf8bc0f736bc9c8e2a9bfa8329b /pcretest.c
parent902b1863bab77eae904bd5db2ba797bbb1ab8501 (diff)
downloadpcre-7777b1557740c6b881bc22d5cd450525a372521d.tar.gz
valgrind: pcretest: Mark data buffer as unaddressable after the end of the data
The data buffer is (usually) bigger than the actual data processed. This patch explicitly marks the excess buffer as unaddressable, so that running under valgrind will signal invalid memory accesses to it. This seems a better solution than memmove'ing the data to the end of the buffer to use the allocated memory region as the valgrind marker. git-svn-id: svn://vcs.exim.org/pcre/code/trunk@1153 2f5784b3-3f2a-0410-8824-cb99058d5e15
Diffstat (limited to 'pcretest.c')
-rw-r--r--pcretest.c25
1 files changed, 22 insertions, 3 deletions
diff --git a/pcretest.c b/pcretest.c
index b797d72..87c3989 100644
--- a/pcretest.c
+++ b/pcretest.c
@@ -4399,6 +4399,14 @@ while (!done)
}
#endif
+#ifdef SUPPORT_VALGRIND
+ /* Mark the dbuffer as addressable but undefined again. */
+ if (dbuffer != NULL)
+ {
+ VALGRIND_MAKE_MEM_UNDEFINED(dbuffer, dbuffer_size * CHAR_SIZE);
+ }
+#endif
+
/* Allocate a buffer to hold the data line. len+1 is an upper bound on
the number of pcre_uchar units that will be needed. */
if (dbuffer == NULL || (size_t)len >= dbuffer_size)
@@ -4820,22 +4828,33 @@ while (!done)
}
#endif
- /* Move the data to the end of the buffer so that a read over the end of
- the buffer will be seen by valgrind, even if it doesn't cause a crash. If
- we are using the POSIX interface, we must include the terminating zero. */
+ /* If we're compiling with explicit valgrind support, Mark the data from after
+ its end to the end of the buffer as unaddressable, so that a read over the end
+ of the buffer will be seen by valgrind, even if it doesn't cause a crash.
+ If we're not building with valgrind support, at least move the data to the end
+ of the buffer so that it might at least cause a crash.
+ If we are using the POSIX interface, we must include the terminating zero. */
bptr = dbuffer;
#if !defined NOPOSIX
if (posix || do_posix)
{
+#ifdef SUPPORT_VALGRIND
+ VALGRIND_MAKE_MEM_NOACCESS(dbuffer + len + 1, dbuffer_size - (len + 1));
+#else
memmove(bptr + dbuffer_size - len - 1, bptr, len + 1);
bptr += dbuffer_size - len - 1;
+#endif
}
else
#endif
{
+#ifdef SUPPORT_VALGRIND
+ VALGRIND_MAKE_MEM_NOACCESS(dbuffer + len * CHAR_SIZE, (dbuffer_size - len) * CHAR_SIZE);
+#else
bptr = memmove(bptr + (dbuffer_size - len) * CHAR_SIZE, bptr, len * CHAR_SIZE);
+#endif
}
if ((all_use_dfa || use_dfa) && find_match_limit)