Catch divide-by-zero in ${eval:...}.
[exim.git] / src / src / expand.c
index 1fd4335da70c74d1b2584f26e54e96f8ee5a0da9..06e0eb0ced0d6dd09124c67242aabe00699cb88b 100644 (file)
@@ -328,9 +328,9 @@ enum {
 /* Type for main variable table */
 
 typedef struct {
-  char *name;
-  int   type;
-  void *value;
+  const char *name;
+  int         type;
+  void       *value;
 } var_entry;
 
 /* Type for entries pointing to address/length pairs. Not currently
@@ -632,9 +632,9 @@ static BOOL malformed_header;
 
 /* For textual hashes */
 
-static char *hashcodes = "abcdefghijklmnopqrtsuvwxyz"
-                         "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
-                         "0123456789";
+static const char *hashcodes = "abcdefghijklmnopqrtsuvwxyz"
+                               "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+                               "0123456789";
 
 enum { HMAC_MD5, HMAC_SHA1 };
 
@@ -3107,7 +3107,16 @@ if (*error == NULL)
     int y = eval_op_unary(&s, decimal, error);
     if (*error != NULL) break;
     if (op == '*') x *= y;
-      else if (op == '/') x /= y;
+      else if (op == '/')
+        {
+        if (y == 0)
+          {
+          *error = US"divide by zero";
+          x = 0;
+          break;
+          }
+        x /= y;
+        }
       else x %= y;
     }
   }