File patch-cve-2022-3559 of Package exim.18132
diff -ru a/src/exim.c b/src/exim.c
--- a/src/exim.c 2021-04-30 14:08:21.000000000 +0200
+++ b/src/exim.c 2022-10-18 14:46:22.278048000 +0200
@@ -1886,8 +1886,6 @@
regex_must_compile(US"^[A-Za-z0-9_/.-]*$", FALSE, TRUE);
#endif
-for (i = 0; i < REGEX_VARS; i++) regex_vars[i] = NULL;
-
/* If the program is called as "mailq" treat it as equivalent to "exim -bp";
this seems to be a generally accepted convention, since one finds symbolic
links called "mailq" in standard OS configurations. */
@@ -5841,7 +5839,7 @@
deliver_localpart_data = deliver_domain_data =
recipient_data = sender_data = NULL;
acl_var_m = NULL;
- for(int i = 0; i < REGEX_VARS; i++) regex_vars[i] = NULL;
+ regex_vars_clear();
store_reset(reset_point);
}
diff -ru a/src/expand.c b/src/expand.c
--- a/src/expand.c 2021-04-30 14:08:21.000000000 +0200
+++ b/src/expand.c 2022-10-18 14:46:22.280498000 +0200
@@ -1888,7 +1888,7 @@
return node ? node->data.ptr : strict_acl_vars ? NULL : US"";
}
-/* Handle $auth<n> variables. */
+/* Handle $auth<n>, $regex<n> variables. */
if (Ustrncmp(name, "auth", 4) == 0)
{
diff -ru a/src/functions.h b/src/functions.h
--- a/src/functions.h 2021-04-30 14:08:21.000000000 +0200
+++ b/src/functions.h 2022-10-18 14:48:19.862220000 +0200
@@ -417,6 +417,7 @@
#endif
extern BOOL regex_match_and_setup(const pcre *, const uschar *, int, int);
extern const pcre *regex_must_compile(const uschar *, BOOL, BOOL);
+extern void regex_vars_clear(void);
extern void retry_add_item(address_item *, uschar *, int);
extern BOOL retry_check_address(const uschar *, host_item *, uschar *, BOOL,
uschar **, uschar **);
diff -ru a/src/globals.c b/src/globals.c
--- a/src/globals.c 2021-04-30 14:08:21.000000000 +0200
+++ b/src/globals.c 2022-10-18 14:47:36.759313000 +0200
@@ -1285,7 +1285,7 @@
#endif
const pcre *regex_ismsgid = NULL;
const pcre *regex_smtp_code = NULL;
-uschar *regex_vars[REGEX_VARS];
+uschar *regex_vars[REGEX_VARS] = { 0 };
#ifdef WHITELIST_D_MACROS
const pcre *regex_whitelisted_macro = NULL;
#endif
diff -ru a/src/regex.c b/src/regex.c
--- a/src/regex.c 2021-04-30 14:08:21.000000000 +0200
+++ b/src/regex.c 2022-10-18 14:46:22.282546000 +0200
@@ -87,18 +87,26 @@
return FAIL;
}
+/* reset expansion variables */
+void
+regex_vars_clear(void)
+{
+regex_match_string = NULL;
+for (int i = 0; i < REGEX_VARS; i++) regex_vars[i] = NULL;
+}
+
+
int
-regex(const uschar **listptr)
+regex(const uschar ** listptr)
{
unsigned long mbox_size;
-FILE *mbox_file;
-pcre_list *re_list_head;
-uschar *linebuffer;
+FILE * mbox_file;
+pcre_list * re_list_head;
+uschar * linebuffer;
long f_pos = 0;
int ret = FAIL;
-/* reset expansion variable */
-regex_match_string = NULL;
+regex_vars_clear();
if (!mime_stream) /* We are in the DATA ACL */
{
@@ -160,14 +168,13 @@
int
mime_regex(const uschar **listptr)
{
-pcre_list *re_list_head = NULL;
-FILE *f;
-uschar *mime_subject = NULL;
+pcre_list * re_list_head = NULL;
+FILE * f;
+uschar * mime_subject = NULL;
int mime_subject_len = 0;
int ret;
-/* reset expansion variable */
-regex_match_string = NULL;
+regex_vars_clear();
/* precompile our regexes */
if (!(re_list_head = compile(*listptr)))
diff -ru a/src/smtp_in.c b/src/smtp_in.c
--- a/src/smtp_in.c 2021-04-30 14:08:21.000000000 +0200
+++ b/src/smtp_in.c 2022-10-18 14:46:22.284374000 +0200
@@ -2161,8 +2161,10 @@
#ifdef SUPPORT_I18N
message_smtputf8 = FALSE;
#endif
+regex_vars_clear();
body_linecount = body_zerocount = 0;
+lookup_value = NULL; /* Can be set by ACL */
sender_rate = sender_rate_limit = sender_rate_period = NULL;
ratelimiters_mail = NULL; /* Updated by ratelimit ACL condition */
/* Note that ratelimiters_conn persists across resets. */