From 51f9c07cd341c9c1a09b3816df988c6f44477c99 Mon Sep 17 00:00:00 2001 From: Jeremy Harris Date: Tue, 11 Apr 2023 11:59:08 +0100 Subject: [PATCH] Fix ${srs_encode ..} for mod-1024 day zero --- doc/ChangeLog | 3 +++ src/expand.c | 10 ++++------ 2 files changed, 7 insertions(+), 6 deletions(-) --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -54,10 +54,13 @@ JH/20 Fix TLSA lookups. Previously dns_ JH/23 Fix crash in string expansions. Previously, if an empty variable was immediately followed by an expansion operator, a null-indirection read was done, killing the process. +JH/27 Fix ${srs_encode ..}. Previously it would give a bad result for one day + every 1024 days. + Exim version 4.96 ----------------- JH/01 Move the wait-for-next-tick (needed for unique message IDs) from --- a/src/expand.c +++ b/src/expand.c @@ -3440,11 +3440,11 @@ switch(cond_type = identify_operator(&s, case 3: return NULL; } /* Match the given local_part against the SRS-encoded pattern */ - re = regex_must_compile(US"^(?i)SRS0=([^=]+)=([A-Z2-7]+)=([^=]*)=(.*)$", + re = regex_must_compile(US"^(?i)SRS0=([^=]+)=([A-Z2-7]{2})=([^=]*)=(.*)$", TRUE, FALSE); md = pcre2_match_data_create(4+1, pcre_gen_ctx); if (pcre2_match(re, sub[0], PCRE2_ZERO_TERMINATED, 0, PCRE_EOPT, md, pcre_mtc_ctx) < 0) { @@ -6957,17 +6957,15 @@ while (*s) /* ${base32:${eval:$tod_epoch/86400&0x3ff}}= */ { struct timeval now; unsigned long i; - gstring * h = NULL; gettimeofday(&now, NULL); - for (unsigned long i = (now.tv_sec / 86400) & 0x3ff; i; i >>= 5) - h = string_catn(h, &base32_chars[i & 0x1f], 1); - if (h) while (h->ptr > 0) - g = string_catn(g, &h->s[--h->ptr], 1); + i = (now.tv_sec / 86400) & 0x3ff; + g = string_catn(g, &base32_chars[i >> 5], 1); + g = string_catn(g, &base32_chars[i & 0x1f], 1); } g = string_catn(g, US"=", 1); /* ${domain:$return_path}=${local_part:$return_path} */ {