Revision: 1153
http://vcs.pcre.org/viewvc?view=rev&revision=1153
Author: chpe
Date: 2012-10-21 17:53:57 +0100 (Sun, 21 Oct 2012)
Log Message:
-----------
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.
Modified Paths:
--------------
code/trunk/pcretest.c
Modified: code/trunk/pcretest.c
===================================================================
--- code/trunk/pcretest.c 2012-10-21 16:53:51 UTC (rev 1152)
+++ code/trunk/pcretest.c 2012-10-21 16:53:57 UTC (rev 1153)
@@ -4399,6 +4399,14 @@
}
#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 @@
}
#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)