[Pcre-svn] [743] code/trunk: Fix valgrind warnings for unset…

Inizio della pagina
Delete this message
Autore: Subversion repository
Data:  
To: pcre-svn
Oggetto: [Pcre-svn] [743] code/trunk: Fix valgrind warnings for unset padding at the end of the pcre2_real_code
Revision: 743
          http://www.exim.org/viewvc/pcre2?view=rev&revision=743
Author:   ph10
Date:     2017-04-12 14:48:11 +0100 (Wed, 12 Apr 2017)
Log Message:
-----------
Fix valgrind warnings for unset padding at the end of the pcre2_real_code 
structure.


Modified Paths:
--------------
    code/trunk/ChangeLog
    code/trunk/src/pcre2_compile.c


Modified: code/trunk/ChangeLog
===================================================================
--- code/trunk/ChangeLog    2017-04-12 13:26:23 UTC (rev 742)
+++ code/trunk/ChangeLog    2017-04-12 13:48:11 UTC (rev 743)
@@ -126,7 +126,12 @@
 heap limit along with other pattern information, and to find the minimum when 
 the find_limits modifier is set.


+23. Write to the last 8 bytes of the pcre2_real_code structure when a compiled
+pattern is set up so as to initialize any padding the compiler might have
+included. This avoids valgrind warnings when a compiled pattern is copied, in
+particular when it is serialized.

+
Version 10.23 14-February-2017
------------------------------


Modified: code/trunk/src/pcre2_compile.c
===================================================================
--- code/trunk/src/pcre2_compile.c    2017-04-12 13:26:23 UTC (rev 742)
+++ code/trunk/src/pcre2_compile.c    2017-04-12 13:48:11 UTC (rev 743)
@@ -9283,7 +9283,14 @@
   errorcode = ERR21;
   goto HAD_CB_ERROR;
   }
+  
+/* The compiler may put padding at the end of the pcre2_real_code structure in 
+order to round it up to a multiple of 4 or 8 bytes. This means that when a 
+compiled pattern is copied (for example, when serialized) undefined bytes are 
+read, and this annoys debuggers such as valgrind. To avoid this, we explicitly 
+write to the last 8 bytes of the structure before setting the fields. */


+memset((char *)re + sizeof(pcre2_real_code) - 8, 0, 8);
re->memctl = ccontext->memctl;
re->tables = tables;
re->executable_jit = NULL;