From e105a0f83fc47525421b5d7b573f74ad62bc80b0 Mon Sep 17 00:00:00 2001 From: "Philip.Hazel" Date: Tue, 21 Mar 2017 16:25:01 +0000 Subject: [PATCH] Fix memory leak when deserializing invalid data (Bugzilla 2075). --- ChangeLog | 2 ++ src/pcre2_serialize.c | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 4a9f6c2..cf58f42 100644 --- a/ChangeLog +++ b/ChangeLog @@ -71,6 +71,8 @@ available, and into a new section that is always compiled for Windows. 10. In pcre2test, explicitly close the file after an error during serialization or deserialization (the "load" or "save" commands). +11. Fix memory leak in pcre2_serialize_decode() when the input is invalid. + Version 10.23 14-February-2017 ------------------------------ diff --git a/src/pcre2_serialize.c b/src/pcre2_serialize.c index 0af26d8..d2cc603 100644 --- a/src/pcre2_serialize.c +++ b/src/pcre2_serialize.c @@ -7,7 +7,7 @@ and semantics are as close as possible to those of the Perl 5 language. Written by Philip Hazel Original API code Copyright (c) 1997-2012 University of Cambridge - New API code Copyright (c) 2016 University of Cambridge + New API code Copyright (c) 2016-2017 University of Cambridge ----------------------------------------------------------------------------- Redistribution and use in source and binary forms, with or without @@ -214,7 +214,10 @@ for (i = 0; i < number_of_codes; i++) if (dst_re->magic_number != MAGIC_NUMBER || dst_re->name_entry_size > MAX_NAME_SIZE + IMM2_SIZE + 1 || dst_re->name_count > MAX_NAME_COUNT) + { + memctl->free(dst_re, memctl->memory_data); return PCRE2_ERROR_BADSERIALIZEDDATA; + } /* At the moment only one table is supported. */