summaryrefslogtreecommitdiff
path: root/glib/tests/regex.c
diff options
context:
space:
mode:
authorMarco Trevisan (Treviño) <mail@3v1n0.net>2022-09-06 17:16:07 +0200
committerMarco Trevisan (Treviño) <mail@3v1n0.net>2022-09-12 13:55:39 +0200
commit1f88976610d5bcc15ad58c9345848d736d64fd55 (patch)
tree931e89b580d55f13ddaaa24b397025701d2115a2 /glib/tests/regex.c
parent1185a1304a88319b58359105f2c1038ae4d7edce (diff)
downloadglib-1f88976610d5bcc15ad58c9345848d736d64fd55.tar.gz
gregex: Do not try access the undefined match offsets if we have no match
In case we're getting NO-MATCH "errors", we were still recomputing the match offsets and taking decisions based on that, that might lead to undefined behavior. Avoid this by just returning early a FALSE result (but with no error) in case there's no result to proceed on. Fixes: #2741
Diffstat (limited to 'glib/tests/regex.c')
-rw-r--r--glib/tests/regex.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/glib/tests/regex.c b/glib/tests/regex.c
index 10daa7814..291c21b4c 100644
--- a/glib/tests/regex.c
+++ b/glib/tests/regex.c
@@ -1669,6 +1669,12 @@ test_class (void)
res = g_match_info_next (match, NULL);
g_assert (!res);
+ /* Accessing match again should not crash */
+ g_test_expect_message ("GLib", G_LOG_LEVEL_CRITICAL,
+ "*match_info->pos >= 0*");
+ g_assert_false (g_match_info_next (match, NULL));
+ g_test_assert_expected_messages ();
+
g_match_info_free (match);
g_regex_unref (regex);
}