fix some pcre2 error

This commit is contained in:
han_hui_hui 2022-12-27 02:17:24 +00:00
parent 40fbbaa66b
commit f5839568d3
6 changed files with 358 additions and 1 deletions

View File

@ -0,0 +1,57 @@
From a164b49532957359c781ab56c3e1690f65f40788 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Guido=20G=C3=BCnther?= <agx@sigxcpu.org>
Date: Fri, 23 Sep 2022 14:48:07 +0200
Subject: [PATCH] gregex: Allow G_REGEX_JAVASCRIPT_COMPAT in compile mask for
g_regex_new
The flag is still ignored but this way we properly deprecate
at compile time without raising an unexpected criticals at runtime:
g_regex_new: assertion '(compile_options & ~G_REGEX_COMPILE_MASK) == 0' failed
and then failing to create the regex completely.
Fixes 8d5a44dc8 ("replace pcre1 with pcre2")
Conflict:NA
Reference:https://gitlab.gnome.org/GNOME/glib/-/commit/a164b49532957359c781ab56c3e1690f65f40788
---
glib/gregex.c | 5 ++++-
glib/tests/regex.c | 4 ++++
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/glib/gregex.c b/glib/gregex.c
index 220a1a11ac..6b22f1f151 100644
--- a/glib/gregex.c
+++ b/glib/gregex.c
@@ -1684,7 +1684,10 @@ g_regex_new (const gchar *pattern,
g_return_val_if_fail (pattern != NULL, NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
- g_return_val_if_fail ((compile_options & ~G_REGEX_COMPILE_MASK) == 0, NULL);
+G_GNUC_BEGIN_IGNORE_DEPRECATIONS
+ g_return_val_if_fail ((compile_options & ~(G_REGEX_COMPILE_MASK |
+ G_REGEX_JAVASCRIPT_COMPAT)) == 0, NULL);
+G_GNUC_END_IGNORE_DEPRECATIONS
g_return_val_if_fail ((match_options & ~G_REGEX_MATCH_MASK) == 0, NULL);
if (g_once_init_enter (&initialised))
diff --git a/glib/tests/regex.c b/glib/tests/regex.c
index 9803d49659..f2e1a04ada 100644
--- a/glib/tests/regex.c
+++ b/glib/tests/regex.c
@@ -2542,6 +2542,10 @@ main (int argc, char *argv[])
TEST_NEW_CHECK_FLAGS ("(*BSR_ANYCRLF)a", 0, 0, G_REGEX_BSR_ANYCRLF, 0);
TEST_NEW_CHECK_FLAGS ("(*BSR_UNICODE)a", 0, 0, 0 /* this is the default in GRegex */, 0);
TEST_NEW_CHECK_FLAGS ("(*NO_START_OPT)a", 0, 0, 0 /* not exposed in GRegex */, 0);
+ /* Make sure we ignore deprecated G_REGEX_JAVASCRIPT_COMPAT */
+G_GNUC_BEGIN_IGNORE_DEPRECATIONS
+ TEST_NEW_CHECK_FLAGS ("a", G_REGEX_JAVASCRIPT_COMPAT, 0, 0, 0);
+G_GNUC_END_IGNORE_DEPRECATIONS
/* TEST_NEW_FAIL(pattern, compile_opts, expected_error) */
TEST_NEW_FAIL("(", 0, G_REGEX_ERROR_UNMATCHED_PARENTHESIS);
--
GitLab

View File

@ -0,0 +1,40 @@
From 664ee9ca6afcc3e08c99f0918982e9d2e22f34a8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Guido=20G=C3=BCnther?= <agx@sigxcpu.org>
Date: Fri, 23 Sep 2022 15:27:49 +0200
Subject: [PATCH] gregex: Drop explanation G_REGEX_JAVASCRIPT_COMPAT
It's not supported as of glib 2.74
Conflict:NA
Reference:https://gitlab.gnome.org/GNOME/glib/-/commit/664ee9ca6afcc3e08c99f0918982e9d2e22f34a8
---
glib/gregex.c | 12 ------------
1 file changed, 12 deletions(-)
diff --git a/glib/gregex.c b/glib/gregex.c
index 6b22f1f151..50abeee89f 100644
--- a/glib/gregex.c
+++ b/glib/gregex.c
@@ -89,18 +89,6 @@
* unescaped "#" outside a character class is encountered. This indicates
* a comment that lasts until after the next newline.
*
- * When setting the %G_REGEX_JAVASCRIPT_COMPAT flag, pattern syntax and pattern
- * matching is changed to be compatible with the way that regular expressions
- * work in JavaScript. More precisely, a lonely ']' character in the pattern
- * is a syntax error; the '\x' escape only allows 0 to 2 hexadecimal digits, and
- * you must use the '\u' escape sequence with 4 hex digits to specify a unicode
- * codepoint instead of '\x' or 'x{....}'. If '\x' or '\u' are not followed by
- * the specified number of hex digits, they match 'x' and 'u' literally; also
- * '\U' always matches 'U' instead of being an error in the pattern. Finally,
- * pattern matching is modified so that back references to an unset subpattern
- * group produces a match with the empty string instead of an error. See
- * pcreapi(3) for more information.
- *
* Creating and manipulating the same #GRegex structure from different
* threads is not a problem as #GRegex does not modify its internal
* state between creation and destruction, on the other hand #GMatchInfo
--
GitLab

View File

@ -0,0 +1,34 @@
From 4fca3bba8f38627ee13b99b0b5093b73a2052e77 Mon Sep 17 00:00:00 2001
From: Philip Withnall <pwithnall@endlessos.org>
Date: Tue, 18 Oct 2022 15:05:30 +0100
Subject: [PATCH] gregex: Remove an unreachable return statement
Spotted by Coverity.
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
Coverity CID: #1497916
Conflict:NA
Reference:https://gitlab.gnome.org/GNOME/glib/-/commit/4fca3bba8f38627ee13b99b0b5093b73a2052e77
---
glib/gregex.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/glib/gregex.c b/glib/gregex.c
index 41ad675a76..53eda2b19d 100644
--- a/glib/gregex.c
+++ b/glib/gregex.c
@@ -947,7 +947,7 @@ enable_jit_with_match_options (GRegex *regex,
break;
}
- return regex->jit_status;
+ g_assert_not_reached ();
}
/**
--
GitLab

View File

@ -0,0 +1,187 @@
From 6caf952e48dbed40b5dcff01a94f57ba079b526c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= <mail@3v1n0.net>
Date: Tue, 20 Sep 2022 18:06:35 +0200
Subject: [PATCH] gregex: Use pcre2 error messages if we don't provide a
specific one
In case we got a compilation or match error we should try to provide
some useful error message, if possible, before returning a quite obscure
"internal error" or "unknown error" string.
So rely on PCRE2 strings even if they're not translated they can provide
better information than the ones we're currently giving.
Related to: https://gitlab.gnome.org/GNOME/glib/-/issues/2691
Related to: https://gitlab.gnome.org/GNOME/glib/-/issues/2760
Conflict:NA
Reference:https://gitlab.gnome.org/GNOME/glib/-/commit/6caf952e48dbed40b5dcff01a94f57ba079b526c
---
glib/gregex.c | 64 ++++++++++++++++++++++++++++++++++++++++------
glib/tests/regex.c | 2 ++
2 files changed, 58 insertions(+), 8 deletions(-)
diff --git a/glib/gregex.c b/glib/gregex.c
index 220a1a11ac..fcc28d62f4 100644
--- a/glib/gregex.c
+++ b/glib/gregex.c
@@ -456,8 +456,25 @@ get_pcre2_bsr_match_options (GRegexMatchFlags match_flags)
return 0;
}
+static char *
+get_pcre2_error_string (int errcode)
+{
+ PCRE2_UCHAR8 error_msg[2048];
+ int err_length;
+
+ err_length = pcre2_get_error_message (errcode, error_msg,
+ G_N_ELEMENTS (error_msg));
+
+ if (err_length <= 0)
+ return NULL;
+
+ /* The array is always filled with a trailing zero */
+ g_assert ((size_t) err_length < G_N_ELEMENTS (error_msg));
+ return g_memdup2 (error_msg, err_length + 1);
+}
+
static const gchar *
-match_error (gint errcode)
+translate_match_error (gint errcode)
{
switch (errcode)
{
@@ -511,7 +528,24 @@ match_error (gint errcode)
default:
break;
}
- return _("unknown error");
+ return NULL;
+}
+
+static char *
+get_match_error_message (int errcode)
+{
+ const char *msg = translate_match_error (errcode);
+ char *error_string;
+
+ if (msg)
+ return g_strdup (msg);
+
+ error_string = get_pcre2_error_string (errcode);
+
+ if (error_string)
+ return error_string;
+
+ return g_strdup (_("unknown error"));
}
static void
@@ -743,7 +777,6 @@ translate_compile_error (gint *errcode, const gchar **errmsg)
case PCRE2_ERROR_INTERNAL_BAD_CODE:
case PCRE2_ERROR_INTERNAL_BAD_CODE_IN_SKIP:
*errcode = G_REGEX_ERROR_INTERNAL;
- *errmsg = _("internal error");
break;
case PCRE2_ERROR_INVALID_SUBPATTERN_NAME:
case PCRE2_ERROR_CLASS_INVALID_RANGE:
@@ -772,12 +805,10 @@ translate_compile_error (gint *errcode, const gchar **errmsg)
case PCRE2_ERROR_BAD_LITERAL_OPTIONS:
default:
*errcode = G_REGEX_ERROR_COMPILE;
- *errmsg = _("internal error");
break;
}
g_assert (*errcode != -1);
- g_assert (*errmsg != NULL);
}
/* GMatchInfo */
@@ -1096,9 +1127,12 @@ g_match_info_next (GMatchInfo *match_info,
if (IS_PCRE2_ERROR (match_info->matches))
{
+ gchar *error_msg = get_match_error_message (match_info->matches);
+
g_set_error (error, G_REGEX_ERROR, G_REGEX_ERROR_MATCH,
_("Error while matching regular expression %s: %s"),
- match_info->regex->pattern, match_error (match_info->matches));
+ match_info->regex->pattern, error_msg);
+ g_clear_pointer (&error_msg, g_free);
return FALSE;
}
else if (match_info->matches == 0)
@@ -1800,11 +1834,20 @@ regex_compile (const gchar *pattern,
{
GError *tmp_error;
gchar *offset_str;
+ gchar *pcre2_errmsg = NULL;
+ int original_errcode;
/* Translate the PCRE error code to GRegexError and use a translated
* error message if possible */
+ original_errcode = errcode;
translate_compile_error (&errcode, &errmsg);
+ if (!errmsg)
+ {
+ errmsg = _("unknown error");
+ pcre2_errmsg = get_pcre2_error_string (original_errcode);
+ }
+
/* PCRE uses byte offsets but we want to show character offsets */
erroffset = g_utf8_pointer_to_offset (pattern, &pattern[erroffset]);
@@ -1812,9 +1855,11 @@ regex_compile (const gchar *pattern,
tmp_error = g_error_new (G_REGEX_ERROR, errcode,
_("Error while compiling regular expression %s "
"at char %s: %s"),
- pattern, offset_str, errmsg);
+ pattern, offset_str,
+ pcre2_errmsg ? pcre2_errmsg : errmsg);
g_propagate_error (error, tmp_error);
g_free (offset_str);
+ g_clear_pointer (&pcre2_errmsg, g_free);
return NULL;
}
@@ -2402,9 +2447,12 @@ g_regex_match_all_full (const GRegex *regex,
}
else if (IS_PCRE2_ERROR (info->matches))
{
+ gchar *error_msg = get_match_error_message (info->matches);
+
g_set_error (error, G_REGEX_ERROR, G_REGEX_ERROR_MATCH,
_("Error while matching regular expression %s: %s"),
- regex->pattern, match_error (info->matches));
+ regex->pattern, error_msg);
+ g_clear_pointer (&error_msg, g_free);
}
else if (info->matches != PCRE2_ERROR_NOMATCH)
{
diff --git a/glib/tests/regex.c b/glib/tests/regex.c
index 9803d49659..52af212f29 100644
--- a/glib/tests/regex.c
+++ b/glib/tests/regex.c
@@ -2560,6 +2560,7 @@ main (int argc, char *argv[])
TEST_NEW_FAIL ("[a-z", 0, G_REGEX_ERROR_UNTERMINATED_CHARACTER_CLASS);
TEST_NEW_FAIL ("[\\B]", 0, G_REGEX_ERROR_INVALID_ESCAPE_IN_CHARACTER_CLASS);
TEST_NEW_FAIL ("[z-a]", 0, G_REGEX_ERROR_RANGE_OUT_OF_ORDER);
+ TEST_NEW_FAIL ("^[[:alnum:]-_.]+$", 0, G_REGEX_ERROR_COMPILE);
TEST_NEW_FAIL ("{2,4}", 0, G_REGEX_ERROR_NOTHING_TO_REPEAT);
TEST_NEW_FAIL ("a(?u)", 0, G_REGEX_ERROR_UNRECOGNIZED_CHARACTER);
TEST_NEW_FAIL ("a(?<$foo)bar", 0, G_REGEX_ERROR_MISSING_SUBPATTERN_NAME);
@@ -2636,6 +2637,7 @@ main (int argc, char *argv[])
TEST_MATCH_SIMPLE("a", "a", G_REGEX_CASELESS, 0, TRUE);
TEST_MATCH_SIMPLE("a", "A", G_REGEX_CASELESS, 0, TRUE);
TEST_MATCH_SIMPLE("\\C\\C", "ab", G_REGEX_OPTIMIZE | G_REGEX_RAW, 0, TRUE);
+ TEST_MATCH_SIMPLE("^[[:alnum:]\\-_.]+$", "admin-foo", 0, 0, TRUE);
/* These are needed to test extended properties. */
TEST_MATCH_SIMPLE(AGRAVE, AGRAVE, G_REGEX_CASELESS, 0, TRUE);
TEST_MATCH_SIMPLE(AGRAVE, AGRAVE_UPPER, G_REGEX_CASELESS, 0, TRUE);
--
GitLab

View File

@ -0,0 +1,31 @@
From 0f869ec5c6bc6cd37a6803cc2299a5845199e758 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= <mail@3v1n0.net>
Date: Wed, 21 Sep 2022 11:33:14 +0200
Subject: [PATCH] regex: Use critical messages if an unexpected NULL parameter
is provided
As programmer error we should be consistent in using criticals.
Conflict:NA
Reference:https://gitlab.gnome.org/GNOME/glib/-/commit/06caf952e48dbed40b5dcff01a94f57ba079b526c
---
glib/gregex.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/glib/gregex.c b/glib/gregex.c
index fcc28d62f4..1baa4e2f18 100644
--- a/glib/gregex.c
+++ b/glib/gregex.c
@@ -483,7 +483,7 @@ translate_match_error (gint errcode)
break;
case PCRE2_ERROR_NULL:
/* NULL argument, this should not happen in GRegex */
- g_warning ("A NULL argument was passed to PCRE");
+ g_critical ("A NULL argument was passed to PCRE");
break;
case PCRE2_ERROR_BADOPTION:
return "bad options";
--
GitLab

View File

@ -1,6 +1,6 @@
Name: glib2 Name: glib2
Version: 2.72.2 Version: 2.72.2
Release: 5 Release: 6
Summary: The core library that forms the basis for projects such as GTK+ and GNOME Summary: The core library that forms the basis for projects such as GTK+ and GNOME
License: LGPLv2+ License: LGPLv2+
URL: http://www.gtk.org URL: http://www.gtk.org
@ -52,6 +52,11 @@ Patch6042: backport-gio-tests-gdbus-peer-Unref-cached-property-GVariant-val
Patch6043: backport-gdesktopappinfo-Unref-the-GDBus-call-results.patch Patch6043: backport-gdesktopappinfo-Unref-the-GDBus-call-results.patch
Patch6044: backport-Handling-collision-between-standard-i-o-file-descriptors-and-newly-created-ones.patch Patch6044: backport-Handling-collision-between-standard-i-o-file-descriptors-and-newly-created-ones.patch
Patch6045: backport-glocalfileoutputstream-Do-not-double-close-an-fd-on-unlink-error.patch Patch6045: backport-glocalfileoutputstream-Do-not-double-close-an-fd-on-unlink-error.patch
Patch6046: backport-gregex-Use-pcre2-error-messages-if-we-dont-provide-a-specific-one.patch
Patch6047: backport-regex-Use-critical-messages-if-an-unexpected-NULL-parameter-is-provided.patch
Patch6048: backport-gregex-Allow-G_REGEX_JAVASCRIPT_COMPAT-in-compile-mask-for-g_regex_new.patch
Patch6049: backport-gregex-Drop-explanation-G_REGEX_JAVASCRIPT_COMPAT.patch
Patch6050: backport-gregex-Remove-an-unreachable-return-statement.patch
BuildRequires: chrpath gcc gcc-c++ gettext perl-interpreter BuildRequires: chrpath gcc gcc-c++ gettext perl-interpreter
BUildRequires: glibc-devel libattr-devel libselinux-devel meson BUildRequires: glibc-devel libattr-devel libselinux-devel meson
@ -244,6 +249,9 @@ glib-compile-schemas %{_datadir}/glib-2.0/schemas &> /dev/null || :
%endif %endif
%changelog %changelog
* Tue Dec 27 2022 hanhuihui <hanhuihui5@huawei.com> - 2.72.2-6
- fix some pcre2 error
* Wed Nov 9 2022 hanhuihui <hanhuihui5@huawei.com> - 2.72.2-5 * Wed Nov 9 2022 hanhuihui <hanhuihui5@huawei.com> - 2.72.2-5
- separate the test and static package from devel package - separate the test and static package from devel package