Fix valgrind warnings for unset padding at the end of the pcre2_real_code

structure.
This commit is contained in:
Philip.Hazel 2017-04-12 13:48:11 +00:00
parent 0cb5a91218
commit bd511d381f
2 changed files with 12 additions and 0 deletions

View File

@ -126,6 +126,11 @@ pcre2_set_heap_limit() or (*LIMIT_HEAP=xxx). Upgraded pcre2test to show the
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
------------------------------

View File

@ -9283,7 +9283,14 @@ if (re == NULL)
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;