[Pcre-svn] [1152] code/trunk/pcre_compile.c: valgrind: Mark …

Startseite
Nachricht löschen
Autor: Subversion repository
Datum:  
To: pcre-svn
Betreff: [Pcre-svn] [1152] code/trunk/pcre_compile.c: valgrind: Mark excess code space as unaddressable
Revision: 1152
          http://vcs.pcre.org/viewvc?view=rev&revision=1152
Author:   chpe
Date:     2012-10-21 17:53:51 +0100 (Sun, 21 Oct 2012)


Log Message:
-----------
valgrind: Mark excess code space as unaddressable

When PCRE compiles a pattern, the required space is first estimated and this
amount of memory is then allocated. For some patterns, the actually required
code space is less than that, which means that the end of the code space is
unused. This patch marks that region as unaddressable, so that valgrind will
signal an error when it is accessed.

Modified Paths:
--------------
    code/trunk/pcre_compile.c


Modified: code/trunk/pcre_compile.c
===================================================================
--- code/trunk/pcre_compile.c    2012-10-21 16:53:46 UTC (rev 1151)
+++ code/trunk/pcre_compile.c    2012-10-21 16:53:51 UTC (rev 1152)
@@ -8129,6 +8129,13 @@
 if (code - codestart > length) errorcode = ERR23;
 #endif


+#ifdef SUPPORT_VALGRIND
+/* If the estimated length exceeds the really used length, mark the extra
+allocated memory as unadressable, so that any out-of-bound reads can be
+detected. */
+VALGRIND_MAKE_MEM_NOACCESS(code, (length - (code - codestart)) * sizeof(pcre_uchar));
+#endif
+
/* Fill in any forward references that are required. There may be repeated
references; optimize for them, as searching a large regex takes time. */