Merge branch 'exim-4.96+security' into master+security
[exim.git] / src / src / expand.c
index ca954ebc29ec3ceb47fdea8739482ce135545c3f..40cc8d73a2afb4f1d37b72635e1844a2d846168f 100644 (file)
@@ -2763,9 +2763,17 @@ switch(cond_type = identify_operator(&s, &opname))
     case ECOND_ISIP:
     case ECOND_ISIP4:
     case ECOND_ISIP6:
-    rc = string_is_ip_address(sub[0], NULL);
-    *yield = ((cond_type == ECOND_ISIP)? (rc != 0) :
-             (cond_type == ECOND_ISIP4)? (rc == 4) : (rc == 6)) == testfor;
+    {
+      const uschar *errp;
+      const uschar **errpp;
+      DEBUG(D_expand) errpp = &errp; else errpp = 0;
+      if (0 == (rc = string_is_ip_addressX(sub[0], NULL, errpp)))
+        DEBUG(D_expand) debug_printf("failed: %s\n", errp);
+
+      *yield = ( cond_type == ECOND_ISIP  ? rc != 0 :
+                 cond_type == ECOND_ISIP4 ? rc == 4 : rc == 6) == testfor;
+    }
+
     break;
 
     /* Various authentication tests - all optionally compiled */
@@ -3583,53 +3591,50 @@ switch(cond_type = identify_operator(&s, &opname))
     /* If a zero-length secret was given, we're done.  Otherwise carry on
     and validate the given SRS local_part againt our secret. */
 
-    if (!*sub[1])
+    if (*sub[1])
       {
-      boolvalue = TRUE;
-      goto srs_result;
-      }
+      /* check the timestamp */
+       {
+       struct timeval now;
+       uschar * ss = sub[0] + ovec[4]; /* substring 2, the timestamp */
+       long d;
+       int n;
 
-    /* check the timestamp */
-      {
-      struct timeval now;
-      uschar * ss = sub[0] + ovec[4];  /* substring 2, the timestamp */
-      long d;
-      int n;
+       gettimeofday(&now, NULL);
+       now.tv_sec /= 86400;                    /* days since epoch */
 
-      gettimeofday(&now, NULL);
-      now.tv_sec /= 86400;             /* days since epoch */
+       /* Decode substring 2 from base32 to a number */
 
-      /* Decode substring 2 from base32 to a number */
+       for (d = 0, n = ovec[5]-ovec[4]; n; n--)
+         {
+         uschar * t = Ustrchr(base32_chars, *ss++);
+         d = d * 32 + (t - base32_chars);
+         }
 
-      for (d = 0, n = ovec[5]-ovec[4]; n; n--)
-       {
-       uschar * t = Ustrchr(base32_chars, *ss++);
-       d = d * 32 + (t - base32_chars);
+       if (((now.tv_sec - d) & 0x3ff) > 10)    /* days since SRS generated */
+         {
+         DEBUG(D_expand) debug_printf("SRS too old\n");
+         goto srs_result;
+         }
        }
 
-      if (((now.tv_sec - d) & 0x3ff) > 10)     /* days since SRS generated */
+      /* check length of substring 1, the offered checksum */
+
+      if (ovec[3]-ovec[2] != 4)
        {
-       DEBUG(D_expand) debug_printf("SRS too old\n");
+       DEBUG(D_expand) debug_printf("SRS checksum wrong size\n");
        goto srs_result;
        }
-      }
 
-    /* check length of substring 1, the offered checksum */
+      /* Hash the address with our secret, and compare that computed checksum
+      with the one extracted from the arg */
 
-    if (ovec[3]-ovec[2] != 4)
-      {
-      DEBUG(D_expand) debug_printf("SRS checksum wrong size\n");
-      goto srs_result;
-      }
-
-    /* Hash the address with our secret, and compare that computed checksum
-    with the one extracted from the arg */
-
-    hmac_md5(sub[1], srs_recipient, cksum, sizeof(cksum));
-    if (Ustrncmp(cksum, sub[0] + ovec[2], 4) != 0)
-      {
-      DEBUG(D_expand) debug_printf("SRS checksum mismatch\n");
-      goto srs_result;
+      hmac_md5(sub[1], srs_recipient, cksum, sizeof(cksum));
+      if (Ustrncmp(cksum, sub[0] + ovec[2], 4) != 0)
+       {
+       DEBUG(D_expand) debug_printf("SRS checksum mismatch\n");
+       goto srs_result;
+       }
       }
     boolvalue = TRUE;
 
@@ -5646,8 +5651,6 @@ while (*s)
       FILE * f;
       const uschar * arg, ** argv;
       unsigned late_expand = TSUC_EXPAND_ARGS | TSUC_ALLOW_TAINTED_ARGS | TSUC_ALLOW_RECIPIENTS;
-      uschar * save_value = lookup_value;
-      int yesno;
 
       if (expand_forbid & RDO_RUN)
         {
@@ -5770,24 +5773,20 @@ while (*s)
             expand_string_message = string_sprintf("command killed by signal %d",
               -runrc);
 
-         lookup_value = save_value;
           goto EXPAND_FAILED;
           }
         }
 
       /* Process the yes/no strings; $value may be useful in both cases */
 
-      yesno = process_yesno(
+      switch(process_yesno(
                flags,                  /* were previously skipping */
                runrc == 0,             /* success/failure indicator */
                lookup_value,           /* value to reset for string2 */
                &s,                     /* input pointer */
                &yield,                 /* output pointer */
                US"run",                        /* condition type */
-              &resetok);
-      lookup_value = save_value;
-
-      switch(yesno)
+              &resetok))
         {
         case 1: goto EXPAND_FAILED;          /* when all is well, the */
         case 2: goto EXPAND_FAILED_CURLY;    /* returned value is 0 */
@@ -5813,16 +5812,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];
           }
         }
 
@@ -6574,6 +6572,7 @@ while (*s)
        goto EXPAND_FAILED_CURLY;                                       /*}*/
        }
 
+      DEBUG(D_expand) debug_printf_indent("%s: evaluate input list list\n", name);
       if (!(list = expand_string_internal(s,
              ESI_BRACE_ENDS | ESI_HONOR_DOLLAR | flags, &s, &resetok, NULL)))
        goto EXPAND_FAILED;                                             /*{{*/
@@ -6593,6 +6592,7 @@ while (*s)
          expand_string_message = US"missing '{' for second arg of reduce";
          goto EXPAND_FAILED_CURLY;                                     /*}*/
          }
+       DEBUG(D_expand) debug_printf_indent("reduce: initial result list\n");
         t = expand_string_internal(s,
              ESI_BRACE_ENDS | ESI_HONOR_DOLLAR | flags, &s, &resetok, NULL);
         if (!t) goto EXPAND_FAILED;
@@ -6620,6 +6620,7 @@ while (*s)
       condition for real. For EITEM_MAP and EITEM_REDUCE, do the same, using
       the normal internal expansion function. */
 
+      DEBUG(D_expand) debug_printf_indent("%s: find end of conditionn\n", name);
       if (item_type != EITEM_FILTER)
         temp = expand_string_internal(s,
          ESI_BRACE_ENDS | ESI_HONOR_DOLLAR | ESI_SKIPPING, &s, &resetok, NULL);
@@ -8141,7 +8142,7 @@ NOT_ITEM: ;
        case EOP_BASE64D:
          {
          uschar * s;
-         int len = b64decode(sub, &s);
+         int len = b64decode(sub, &s, sub);
          if (len < 0)
            {
            expand_string_message = string_sprintf("string \"%s\" is not "