[glib/wip/3v1n0/regex-pcre2-flags-fixes: 2/11] gregex: Fix a potential PCRE2 code leak on reallocation failures
- From: Marco Trevisan <marcotrevi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/wip/3v1n0/regex-pcre2-flags-fixes: 2/11] gregex: Fix a potential PCRE2 code leak on reallocation failures
- Date: Fri, 9 Sep 2022 16:52:08 +0000 (UTC)
commit e377903f06a055936bd75bf7469dc9f916f9084e
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date: Tue Sep 6 17:20:45 2022 +0200
gregex: Fix a potential PCRE2 code leak on reallocation failures
In case recalc_match_offsets() failed we were just returning, but in
such case, per the documentation we should still set the match_info (if
provided) and free the pcre2 code instance.
So let's just break the loop we're in it, as if we we've no matches set.
This also avoids re-allocating the offsets array and potentially
accessing to unset data.
glib/gregex.c | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
---
diff --git a/glib/gregex.c b/glib/gregex.c
index f2a5b5fd1c..6f3ee88122 100644
--- a/glib/gregex.c
+++ b/glib/gregex.c
@@ -2337,13 +2337,6 @@ g_regex_match_all_full (const GRegex *regex,
info->match_data,
info->match_context,
info->workspace, info->n_workspace);
-
- if (!recalc_match_offsets (info, error))
- {
- g_match_info_free (info);
- return FALSE;
- }
-
if (info->matches == PCRE2_ERROR_DFA_WSSIZE)
{
/* info->workspace is too small. */
@@ -2370,6 +2363,11 @@ g_regex_match_all_full (const GRegex *regex,
_("Error while matching regular expression %s: %s"),
regex->pattern, match_error (info->matches));
}
+ else if (info->matches > 0)
+ {
+ if (!recalc_match_offsets (info, error))
+ info->matches = PCRE2_ERROR_NOMATCH;
+ }
}
pcre2_code_free (pcre_re);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]