[Pcre-svn] [985] code/trunk: Zero pointers in serialized pat…

Top Page
Delete this message
Author: Subversion repository
Date:  
To: pcre-svn
Subject: [Pcre-svn] [985] code/trunk: Zero pointers in serialized patterns, for consistency.
Revision: 985
          http://www.exim.org/viewvc/pcre2?view=rev&revision=985
Author:   ph10
Date:     2018-08-15 19:03:29 +0100 (Wed, 15 Aug 2018)
Log Message:
-----------
Zero pointers in serialized patterns, for consistency.


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


Modified: code/trunk/ChangeLog
===================================================================
--- code/trunk/ChangeLog    2018-08-13 14:20:46 UTC (rev 984)
+++ code/trunk/ChangeLog    2018-08-15 18:03:29 UTC (rev 985)
@@ -155,7 +155,12 @@
 an emulation function when there is no memmove(). The emulation makes use of
 bcopy() when available.


+34. When serializing a pattern, set the memctl, executable_jit, and tables
+fields (that is, all the fields that contain pointers) to zeros so that the
+result of serializing is always the same. These fields are re-set when the
+pattern is deserialized.

+
Version 10.31 12-February-2018
------------------------------


Modified: code/trunk/src/pcre2_serialize.c
===================================================================
--- code/trunk/src/pcre2_serialize.c    2018-08-13 14:20:46 UTC (rev 984)
+++ code/trunk/src/pcre2_serialize.c    2018-08-15 18:03:29 UTC (rev 985)
@@ -127,7 +127,21 @@
 for (i = 0; i < number_of_codes; i++)
   {
   re = (const pcre2_real_code *)(codes[i]);
-  memcpy(dst_bytes, (char *)re, re->blocksize);
+  (void)memcpy(dst_bytes, (char *)re, re->blocksize);
+  
+  /* Certain fields in the compiled code block are re-set during 
+  deserialization. In order to ensure that the serialized data stream is always 
+  the same for the same pattern, set them to zero here. We can't assume the 
+  copy of the pattern is correctly aligned for accessing the fields as part of 
+  a structure. */
+  
+  (void)memset((void *)(dst_bytes + offsetof(pcre2_real_code, memctl)), 0, 
+    sizeof(pcre2_memctl));
+  (void)memset((void *)(dst_bytes + offsetof(pcre2_real_code, tables)), 0, 
+    sizeof(uint8_t *));
+  (void)memset((void *)(dst_bytes + offsetof(pcre2_real_code, executable_jit)),
+    0, sizeof(void *));        
+ 
   dst_bytes += re->blocksize;
   }