|
| 1 | +From 42632cb7d0103fbf871fb698e7648ba925eec254 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Alexander Bokovoy <abokovoy@redhat.com> |
| 3 | +Date: Mon, 24 Mar 2025 09:48:19 +0200 |
| 4 | +Subject: [PATCH] CVE-2025-2588: return _REG_ENOSYS if no specific error was |
| 5 | + set yet parse_regexp failed |
| 6 | + |
| 7 | +parse_regexp() supposed to set an error on the parser state in case of a |
| 8 | +failure. If no specific error was set, return _REG_ENOSYS to indicate a |
| 9 | +generic failure. |
| 10 | + |
| 11 | +Fixes: https://github.com/hercules-team/augeas/issues/671 |
| 12 | +Fixes: https://github.com/hercules-team/augeas/issues/778 |
| 13 | +Fixes: https://github.com/hercules-team/augeas/issues/852 |
| 14 | + |
| 15 | +Signed-off-by: Alexander Bokovoy <abokovoy@redhat.com> |
| 16 | +--- |
| 17 | + src/fa.c | 3 +++ |
| 18 | + src/fa.h | 3 ++- |
| 19 | + tests/fatest.c | 6 ++++++ |
| 20 | + 3 files changed, 11 insertions(+), 1 deletion(-) |
| 21 | + |
| 22 | +diff --git a/src/fa.c b/src/fa.c |
| 23 | +index 66ac70784..14f2472ad 100644 |
| 24 | +--- a/src/fa.c |
| 25 | ++++ b/src/fa.c |
| 26 | +@@ -32,6 +32,7 @@ |
| 27 | + #include <config.h> |
| 28 | + #include <limits.h> |
| 29 | + #include <ctype.h> |
| 30 | ++#include <regex.h> |
| 31 | + #include <stdbool.h> |
| 32 | + |
| 33 | + #include "internal.h" |
| 34 | +@@ -3550,6 +3551,8 @@ static struct re *parse_regexp(struct re_parse *parse) { |
| 35 | + return re; |
| 36 | + |
| 37 | + error: |
| 38 | ++ if (re == NULL && parse->error == REG_NOERROR) |
| 39 | ++ parse->error = _REG_ENOSYS; |
| 40 | + re_unref(re); |
| 41 | + return NULL; |
| 42 | + } |
| 43 | +diff --git a/src/fa.h b/src/fa.h |
| 44 | +index 1fd754ad0..89c9b17e9 100644 |
| 45 | +--- a/src/fa.h |
| 46 | ++++ b/src/fa.h |
| 47 | +@@ -81,7 +81,8 @@ extern int fa_minimization_algorithm; |
| 48 | + * |
| 49 | + * On success, FA points to the newly allocated automaton constructed for |
| 50 | + * RE, and the function returns REG_NOERROR. Otherwise, FA is NULL, and the |
| 51 | +- * return value indicates the error. |
| 52 | ++ * return value indicates the error. Special value _REG_ENOSYS indicates |
| 53 | ++ * fa_compile() couldn't identify the syntax issue with regexp. |
| 54 | + * |
| 55 | + * The FA is case sensitive. Call FA_NOCASE to switch it to |
| 56 | + * case-insensitive. |
| 57 | +diff --git a/tests/fatest.c b/tests/fatest.c |
| 58 | +index 0c9ca7696..6717af8f4 100644 |
| 59 | +--- a/tests/fatest.c |
| 60 | ++++ b/tests/fatest.c |
| 61 | +@@ -589,6 +589,7 @@ static void testExpandNoCase(CuTest *tc) { |
| 62 | + const char *p1 = "aB"; |
| 63 | + const char *p2 = "[a-cUV]"; |
| 64 | + const char *p3 = "[^a-z]"; |
| 65 | ++ const char *wrong_regexp = "{&.{"; |
| 66 | + char *s; |
| 67 | + size_t len; |
| 68 | + int r; |
| 69 | +@@ -607,6 +608,11 @@ static void testExpandNoCase(CuTest *tc) { |
| 70 | + CuAssertIntEquals(tc, 0, r); |
| 71 | + CuAssertStrEquals(tc, "[^A-Za-z]", s); |
| 72 | + free(s); |
| 73 | ++ |
| 74 | ++ /* Test that fa_expand_nocase does return _REG_ENOSYS */ |
| 75 | ++ r = fa_expand_nocase(wrong_regexp, strlen(wrong_regexp), &s, &len); |
| 76 | ++ CuAssertIntEquals(tc, _REG_ENOSYS, r); |
| 77 | ++ free(s); |
| 78 | + } |
| 79 | + |
| 80 | + static void testNoCaseComplement(CuTest *tc) { |
0 commit comments