Skip to content

Commit 73b558c

Browse files
committed
Write padding values to ensure pcre2_serialize_encode() outputs defined values (#826)
Fixes low-severity valgrind error reported in GHSA-q7rw-r7qq-2hx6. Cherry-picked edc111a6831591f68b5355a08cc9df8be8f35304 from upstream https://github.com/PCRE2Project/pcre2 to get this fix into OTP 28.3 and silence valgrind.
1 parent add1523 commit 73b558c

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

erts/emulator/pcre/pcre2_compile_class.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1803,17 +1803,14 @@ if ((xclass_props & XCLASS_REQUIRED) != 0)
18031803
PUT(code, 0, (uint32_t)(char_lists_size >> 1));
18041804
code += LINK_SIZE;
18051805

1806-
#if defined PCRE2_DEBUG || defined SUPPORT_VALGRIND
1806+
/* If we added padding to align the list, initialize the bytes to
1807+
defined values, so the library is valgrind-clean. It could also
1808+
be a security concern for clients calling into PCRE2 via bindings
1809+
from a memory-safe language, if pcre2_serialize_encode() exposes
1810+
uninitialized memory that may contain sensitive information. */
1811+
18071812
if ((char_lists_size & 0x2) != 0)
1808-
{
1809-
/* In debug the unused 16 bit value is set
1810-
to a fixed value and marked unused. */
1811-
((uint16_t*)data)[-1] = 0x5555;
1812-
#ifdef SUPPORT_VALGRIND
1813-
VALGRIND_MAKE_MEM_NOACCESS(data - 2, 2);
1814-
#endif
1815-
}
1816-
#endif
1813+
((uint16_t*)data)[-1] = 0xdead;
18171814

18181815
cb->char_lists_size =
18191816
CLIST_ALIGN_TO(char_lists_size, sizeof(uint32_t));

0 commit comments

Comments
 (0)