SPDX: Mass-update to GPL-2.0-or-later
[exim.git] / src / src / expand.c
index 831ca2b759f877c5b9138653e656ebed8970e6f9..657cf3cb926bc5b91771266b50ff4591d09e61ec 100644 (file)
@@ -5,6 +5,7 @@
 /* Copyright (c) The Exim Maintainers 2020 - 2022 */
 /* Copyright (c) University of Cambridge 1995 - 2018 */
 /* See the file NOTICE for conditions of use and distribution. */
+/* SPDX-License-Identifier: GPL-2.0-or-later */
 
 
 /* Functions for handling string expansion. */
@@ -6544,6 +6545,9 @@ while (*s)
         if (item_type == EITEM_FILTER)
           {
           BOOL condresult;
+         /* the condition could modify $value, as a side-effect */
+         uschar * save_value = lookup_value;
+
           if (!eval_condition(expr, &resetok, &condresult))
             {
             iterate_item = save_iterate_item;
@@ -6552,6 +6556,7 @@ while (*s)
               expand_string_message, name);
             goto EXPAND_FAILED;
             }
+         lookup_value = save_value;
           DEBUG(D_expand) debug_printf_indent("%s: condition is %s\n", name,
             condresult? "true":"false");
           if (condresult)
@@ -6560,14 +6565,12 @@ while (*s)
             continue;               /* FALSE => skip this item */
           }
 
-        /* EITEM_MAP and EITEM_REDUCE */
-
-        else
+        else                   /* EITEM_MAP and EITEM_REDUCE */
           {
+         /* the expansion could modify $value, as a side-effect */
          uschar * t = expand_string_internal(expr,
            ESI_BRACE_ENDS | ESI_HONOR_DOLLAR | flags, NULL, &resetok, NULL);
-          temp = t;
-          if (!temp)
+          if (!(temp = t))
             {
             iterate_item = save_iterate_item;
             expand_string_message = string_sprintf("%s inside \"%s\" item",