mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-10 19:36:18 +01:00
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.
This commit is contained in:
parent
1f88976610
commit
13ad4296ea
@ -2337,13 +2337,6 @@ g_regex_match_all_full (const GRegex *regex,
|
|||||||
info->match_data,
|
info->match_data,
|
||||||
info->match_context,
|
info->match_context,
|
||||||
info->workspace, info->n_workspace);
|
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)
|
if (info->matches == PCRE2_ERROR_DFA_WSSIZE)
|
||||||
{
|
{
|
||||||
/* info->workspace is too small. */
|
/* info->workspace is too small. */
|
||||||
@ -2370,6 +2363,11 @@ g_regex_match_all_full (const GRegex *regex,
|
|||||||
_("Error while matching regular expression %s: %s"),
|
_("Error while matching regular expression %s: %s"),
|
||||||
regex->pattern, match_error (info->matches));
|
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);
|
pcre2_code_free (pcre_re);
|
||||||
|
Loading…
Reference in New Issue
Block a user