[gtksourceview/gnome-3-24] regex: fix potential use of -1 as byte offset
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/gnome-3-24] regex: fix potential use of -1 as byte offset
- Date: Thu, 6 Dec 2018 20:57:57 +0000 (UTC)
commit 23bc81adf6c98f76cc4afb23688bc2397ed0e948
Author: Christian Hergert <chergert redhat com>
Date: Thu Dec 6 12:55:52 2018 -0800
regex: fix potential use of -1 as byte offset
g_match_info_pos() can return TRUE even if there was not a match, and the
start/end position are set to -1.
See g_match_info_fetch_pos() documentation for more information. This fixes
an invalid read warning by -1 in valgrind.
gtksourceview/gtksourceregex.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
---
diff --git a/gtksourceview/gtksourceregex.c b/gtksourceview/gtksourceregex.c
index 3934d199..7d53ceaf 100644
--- a/gtksourceview/gtksourceregex.c
+++ b/gtksourceview/gtksourceregex.c
@@ -334,7 +334,9 @@ _gtk_source_regex_fetch_pos (GtkSourceRegex *regex,
g_assert (regex->resolved);
- if (!g_match_info_fetch_pos (regex->u.regex.match, num, &byte_start_pos, &byte_end_pos))
+ /* g_match_info_fetch_pos() can return TRUE with start_pos/end_pos set to -1 */
+ if (!g_match_info_fetch_pos (regex->u.regex.match, num, &byte_start_pos, &byte_end_pos) ||
+ byte_start_pos == -1 || byte_end_pos == 1)
{
if (start_pos != NULL)
*start_pos = -1;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]