Fix ${tr...} and empty-strings. Bug 3023
authorJeremy Harris <jgh146exb@wizmail.org>
Mon, 11 Sep 2023 14:50:35 +0000 (15:50 +0100)
committerJeremy Harris <jgh146exb@wizmail.org>
Mon, 11 Sep 2023 14:50:35 +0000 (15:50 +0100)
doc/doc-txt/ChangeLog
src/src/expand.c
test/scripts/0000-Basic/0002
test/stdout/0002

index b1b79c2403184288358f3ccc5f1d62d6ea6d81cb..5fcc8ab11b52d487f31ec19370e22ec1fab198f6 100644 (file)
@@ -190,6 +190,9 @@ JH/38 Taint-track intermediate values from the peer in multi-stage authentation
       this resulted in behaviour of LOGIN vs. PLAIN being inconsistent under
       bad coding of authenticators.
 
       this resulted in behaviour of LOGIN vs. PLAIN being inconsistent under
       bad coding of authenticators.
 
+JH/39 Bug 3023: Fix crash induced by some combinations of zero-length strings
+      and ${tr...}.  Found and diagnosed by Heiko Schlichting.
+
 
 Exim version 4.96
 -----------------
 
 Exim version 4.96
 -----------------
index b4a76b3e7649f9573fcb720cd4a6ed711a6652a3..aa8bfe643b9494c6e6de86a8c4ab2728a6482784 100644 (file)
@@ -5807,16 +5807,15 @@ while (*s)
         case 3: goto EXPAND_FAILED;
         }
 
         case 3: goto EXPAND_FAILED;
         }
 
-      yield = string_cat(yield, sub[0]);
-      o2m = Ustrlen(sub[2]) - 1;
-
-      if (o2m >= 0) for (; oldptr < yield->ptr; oldptr++)
+      if (  (yield = string_cat(yield, sub[0]))
+         && (o2m = Ustrlen(sub[2]) - 1) >= 0)
+         for (; oldptr < yield->ptr; oldptr++)
         {
         uschar * m = Ustrrchr(sub[1], yield->s[oldptr]);
         if (m)
           {
           int o = m - sub[1];
         {
         uschar * m = Ustrrchr(sub[1], yield->s[oldptr]);
         if (m)
           {
           int o = m - sub[1];
-          yield->s[oldptr] = sub[2][(o < o2m)? o : o2m];
+          yield->s[oldptr] = sub[2][o < o2m ? o : o2m];
           }
         }
 
           }
         }
 
index dab982253fd833dda040b370eab4c76582d6c07c..b4f2341bb5e21283a10acf092b3da98dca40d9ea 100644 (file)
@@ -714,6 +714,7 @@ abcdea aaa xyz ${tr{abcdea}{aaa}{xyz}}
 abcdea a   z   ${tr{abcdea}{a}{z}}
 abcdea a       ${tr{abcdea}{a}{}}
 abcdea abc z   ${tr{abcdea}{abc}{z}}
 abcdea a   z   ${tr{abcdea}{a}{z}}
 abcdea a       ${tr{abcdea}{a}{}}
 abcdea abc z   ${tr{abcdea}{abc}{z}}
+(null)         '${sg{$header_foobar:${tr{}{}{foobar}}}{}{}}'
 
 # Boolean
 "TrUe"                ${if bool{TrUe}{true}{false}}      EXPECT: true
 
 # Boolean
 "TrUe"                ${if bool{TrUe}{true}{false}}      EXPECT: true
index 5b9de8e5eb4b2bafcb23743f02ddf7eb9cca816f..2d7c828381f81a7c86380e6890989430c6fe51ae 100644 (file)
@@ -696,6 +696,7 @@ newline     tab\134backslash ~tilde\177DEL\200\201.
 > abcdea a   z   zbcdez
 > abcdea a       abcdea
 > abcdea abc z   zzzdez
 > abcdea a   z   zbcdez
 > abcdea a       abcdea
 > abcdea abc z   zzzdez
+> (null)         ''
 > 
 > # Boolean
 > "TrUe"                true      EXPECT: true
 > 
 > # Boolean
 > "TrUe"                true      EXPECT: true