summaryrefslogtreecommitdiffstats
path: root/debian/patches/75_68-Fix-srs_encode-.-for-mod-1024-day-zero.patch
blob: dddd5e9a3853d659036b038223b0badca372d1e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
From 51f9c07cd341c9c1a09b3816df988c6f44477c99 Mon Sep 17 00:00:00 2001
From: Jeremy Harris <jgh146exb@wizmail.org>
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} */
 	  {