diff options
author | Tony Finch <dot@dotat.at> | 2014-07-16 06:13:39 -0700 |
---|---|---|
committer | Todd Lyons <tlyons@exim.org> | 2014-07-16 06:47:37 -0700 |
commit | 7685ce68148a083d7759e78d01aa5198fc099c44 (patch) | |
tree | db9caff0416ba42949180cae25d27a7269dcd9bf /src | |
parent | a2204cac393bb160ae7f253b9bb5280fc35ca3a3 (diff) |
Only expand integers for integer math once
Diffstat (limited to 'src')
-rw-r--r-- | 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 88a5ee399..c6356fbe1 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; |