• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1From c05d09044fb71bdea599c81bf0ae896a5503e76a Mon Sep 17 00:00:00 2001
2From: Marco Trevisan <mail@3v1n0.net>
3Date: Fri, 15 Jul 2022 01:27:33 +0200
4Subject: [PATCH] gregex: Ensure we translate the errcode without asserting on
5 G_REGEX_ERROR_COMPILE
6
7Since commit 8d5a44dc in order to ensure that we were setting the errcode in
8translate_compile_error(), we did an assert checking whether it was a
9valid value, but we assumed that 0 was not a valid error, while it is as
10it's the generic G_REGEX_ERROR_COMPILE.
11
12So, set errcode and errmsg to invalid values before translating and
13ensure we've change them.
14
15Fixes: #2694
16
17Conflict:NA
18Reference:https://gitlab.gnome.org/GNOME/glib/-/commit/c05d09044fb71bdea599c81bf0ae896a5503e76a
19
20---
21 glib/gregex.c      |  8 ++++++--
22 glib/tests/regex.c | 13 +++++++++++++
23 2 files changed, 19 insertions(+), 2 deletions(-)
24
25diff --git a/glib/gregex.c b/glib/gregex.c
26index 5fc7b16bc8..2a54929bf4 100644
27--- a/glib/gregex.c
28+++ b/glib/gregex.c
29@@ -476,8 +476,12 @@ translate_compile_error (gint *errcode, const gchar **errmsg)
30    * Note that there can be more PCRE errors with the same GRegexError
31    * and that some PCRE errors are useless for us.
32    */
33+  gint original_errcode = *errcode;
34
35-  switch (*errcode)
36+  *errcode = -1;
37+  *errmsg = NULL;
38+
39+  switch (original_errcode)
40     {
41     case PCRE2_ERROR_END_BACKSLASH:
42       *errcode = G_REGEX_ERROR_STRAY_BACKSLASH;
43@@ -725,7 +729,7 @@ translate_compile_error (gint *errcode, const gchar **errmsg)
44       break;
45     }
46
47-  g_assert (*errcode != 0);
48+  g_assert (*errcode != -1);
49   g_assert (*errmsg != NULL);
50 }
51
52diff --git a/glib/tests/regex.c b/glib/tests/regex.c
53index 3355f64e54..9a1977b248 100644
54--- a/glib/tests/regex.c
55+++ b/glib/tests/regex.c
56@@ -2187,6 +2187,18 @@ pcre2_ge (guint64 major, guint64 minor)
57     return (pcre2_major > major) || (pcre2_major == major && pcre2_minor >= minor);
58 }
59
60+static void
61+test_compile_errors (void)
62+{
63+  GRegex *regex;
64+  GError *error = NULL;
65+
66+  regex = g_regex_new ("\\o{999}", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
67+  g_assert_null (regex);
68+  g_assert_error (error, G_REGEX_ERROR, G_REGEX_ERROR_COMPILE);
69+  g_clear_error (&error);
70+}
71+
72 int
73 main (int argc, char *argv[])
74 {
75@@ -2204,6 +2216,7 @@ main (int argc, char *argv[])
76   g_test_add_func ("/regex/multiline", test_multiline);
77   g_test_add_func ("/regex/explicit-crlf", test_explicit_crlf);
78   g_test_add_func ("/regex/max-lookbehind", test_max_lookbehind);
79+  g_test_add_func ("/regex/compile-errors", test_compile_errors);
80
81   /* TEST_NEW(pattern, compile_opts, match_opts) */
82 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
83--
84GitLab
85
86