From 808f1b34e17a80010b989e37f27d639d0c1afc4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Mon, 5 Jun 2017 14:43:08 +0300 Subject: [PATCH] Fix use of pcre2_substitute The length parameter is not set to the required string length unless a parameter is set. The previous length should be stored before calling pcre2_substitute. --- utils/skygw_utils.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/utils/skygw_utils.cc b/utils/skygw_utils.cc index 8c5fc59a0..d4f1e13aa 100644 --- a/utils/skygw_utils.cc +++ b/utils/skygw_utils.cc @@ -1181,12 +1181,13 @@ char* remove_mysql_comments(const char** src, const size_t* srcsize, char** dest if ((output || (output = (char*) malloc(len * sizeof (char)))) && (mdata = pcre2_match_data_create_from_pattern(remove_comments_re, NULL))) { + orig_len = len; while (pcre2_substitute(remove_comments_re, (PCRE2_SPTR) * src, orig_len, 0, PCRE2_SUBSTITUTE_GLOBAL, mdata, NULL, replace, PCRE2_ZERO_TERMINATED, (PCRE2_UCHAR8*) output, &len) == PCRE2_ERROR_NOMEMORY) { - char* tmp = (char*) realloc(output, (len = (size_t) (len * BUFFER_GROWTH_RATE + 1))); + char* tmp = (char*) realloc(output, (len = (size_t) (orig_len * BUFFER_GROWTH_RATE + 1))); if (tmp == NULL) { free(output);