[exim-cvs] Fix ${tr...} and empty-strings. Bug 3023

Páxina inicial
Borrar esta mensaxe
Responder a esta mensaxe
Autor: Exim Git Commits Mailing List
Data:  
Para: exim-cvs
Asunto: [exim-cvs] Fix ${tr...} and empty-strings. Bug 3023
Gitweb: https://git.exim.org/exim.git/commitdiff/b015574531cf18b2126edb9da5a99dad659207dd
Commit:     b015574531cf18b2126edb9da5a99dad659207dd
Parent:     cf1e30bc975d646511945e3dd3538fb97637559d
Author:     Jeremy Harris <jgh146exb@???>
AuthorDate: Mon Sep 11 15:50:35 2023 +0100
Committer:  Jeremy Harris <jgh146exb@???>
CommitDate: Mon Sep 11 15:50:35 2023 +0100


    Fix ${tr...} and empty-strings.  Bug 3023
---
 doc/doc-txt/ChangeLog        | 3 +++
 src/src/expand.c             | 9 ++++-----
 test/scripts/0000-Basic/0002 | 1 +
 test/stdout/0002             | 1 +
 4 files changed, 9 insertions(+), 5 deletions(-)


diff --git a/doc/doc-txt/ChangeLog b/doc/doc-txt/ChangeLog
index b1b79c240..5fcc8ab11 100644
--- a/doc/doc-txt/ChangeLog
+++ b/doc/doc-txt/ChangeLog
@@ -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.


+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
 -----------------
diff --git a/src/src/expand.c b/src/src/expand.c
index b4a76b3e7..aa8bfe643 100644
--- a/src/src/expand.c
+++ b/src/src/expand.c
@@ -5807,16 +5807,15 @@ while (*s)
         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];
-          yield->s[oldptr] = sub[2][(o < o2m)? o : o2m];
+          yield->s[oldptr] = sub[2][o < o2m ? o : o2m];
           }
         }


diff --git a/test/scripts/0000-Basic/0002 b/test/scripts/0000-Basic/0002
index dab982253..b4f2341bb 100644
--- a/test/scripts/0000-Basic/0002
+++ b/test/scripts/0000-Basic/0002
@@ -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}}
+(null)         '${sg{$header_foobar:${tr{}{}{foobar}}}{}{}}'


 # Boolean
 "TrUe"                ${if bool{TrUe}{true}{false}}      EXPECT: true
diff --git a/test/stdout/0002 b/test/stdout/0002
index 5b9de8e5e..2d7c82838 100644
--- a/test/stdout/0002
+++ b/test/stdout/0002
@@ -696,6 +696,7 @@ newline    tab\134backslash ~tilde\177DEL\200\201.

 > abcdea a   z   zbcdez
 > abcdea a       abcdea
 > abcdea abc z   zzzdez

+> (null)         ''

>
 > # Boolean
 > "TrUe"                true      EXPECT: true


--
## subscription configuration (requires account):
## https://lists.exim.org/mailman3/postorius/lists/exim-cvs.lists.exim.org/
## unsubscribe (doesn't require an account):
## exim-cvs-unsubscribe@???
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/