[exim-cvs] Only expand integers for integer math once

Pàgina inicial
Delete this message
Reply to this message
Autor: Exim Git Commits Mailing List
Data:  
A: exim-cvs
Assumpte: [exim-cvs] Only expand integers for integer math once
Gitweb: http://git.exim.org/exim.git/commitdiff/7685ce68148a083d7759e78d01aa5198fc099c44
Commit:     7685ce68148a083d7759e78d01aa5198fc099c44
Parent:     a2204cac393bb160ae7f253b9bb5280fc35ca3a3
Author:     Tony Finch <dot@???>
AuthorDate: Wed Jul 16 06:13:39 2014 -0700
Committer:  Todd Lyons <tlyons@???>
CommitDate: Wed Jul 16 06:47:37 2014 -0700


    Only expand integers for integer math once
---
 src/src/expand.c |   31 ++++++++++++++++++++++++++++---
 1 files changed, 28 insertions(+), 3 deletions(-)


diff --git a/src/src/expand.c b/src/src/expand.c
index 88a5ee3..c6356fb 100644
--- a/src/src/expand.c
+++ b/src/src/expand.c
@@ -14,6 +14,7 @@
/* Recursively called function */

static uschar *expand_string_internal(uschar *, BOOL, uschar **, BOOL, BOOL, BOOL *);
+static int_eximarith_t expanded_string_integer(uschar *, BOOL);

 #ifdef STAND_ALONE
 #ifndef SUPPORT_CRYPTEQ
@@ -2445,7 +2446,7 @@ switch(cond_type)
         }
       else
         {
-        num[i] = expand_string_integer(sub[i], FALSE);
+        num[i] = expanded_string_integer(sub[i], FALSE);
         if (expand_string_message != NULL) return NULL;
         }
       }
@@ -6679,7 +6680,7 @@ while (*s != 0)
         int_eximarith_t max;
         uschar *s;


-        max = expand_string_integer(sub, TRUE);
+        max = expanded_string_integer(sub, TRUE);
         if (expand_string_message != NULL)
           goto EXPAND_FAILED;
         s = string_sprintf("%d", vaguely_random_number((int)max));
@@ -6879,8 +6880,32 @@ Returns:  the integer value, or
 int_eximarith_t
 expand_string_integer(uschar *string, BOOL isplus)
 {
+return expanded_string_integer(expand_string(string), isplus);
+}
+
+
+/*************************************************
+ *         Interpret string as an integer        *
+ *************************************************/
+
+/* Convert a string (that has already been expanded) into an integer.
+
+This function is used inside the expansion code.
+
+Arguments:
+  s       the string to be expanded
+  isplus  TRUE if a non-negative number is expected
+
+Returns:  the integer value, or
+          -1 if string is NULL (which implies an expansion error)
+          -2 for an integer interpretation error
+          expand_string_message is set NULL for an OK integer
+*/
+
+static int_eximarith_t
+expanded_string_integer(uschar *s, BOOL isplus)
+{
 int_eximarith_t value;
-uschar *s = expand_string(string);
 uschar *msg = US"invalid integer \"%s\"";
 uschar *endptr;