From: Thierry FOURNIER Date: Mon, 27 Jan 2014 17:20:48 +0000 (+0100) Subject: BUG/MINOR: sample: The c_str2int converter does not fail if the entry is not an integer X-Git-Tag: v1.5-dev22~25 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=60bb020d702d04076ff16c9cf09c67c6bf7bb638;p=thirdparty%2Fhaproxy.git BUG/MINOR: sample: The c_str2int converter does not fail if the entry is not an integer If the string not start with a number, the converter fails. In other, it converts a maximum of characters to a number and stop to the first character that not match a number. --- diff --git a/src/sample.c b/src/sample.c index 2a114d9af6..f0a346ae6a 100644 --- a/src/sample.c +++ b/src/sample.c @@ -549,11 +549,17 @@ static int c_str2int(struct sample *smp) int i; uint32_t ret = 0; + if (smp->data.str.len == 0) + return 0; + for (i = 0; i < smp->data.str.len; i++) { uint32_t val = smp->data.str.str[i] - '0'; - if (val > 9) + if (val > 9) { + if (i == 0) + return 0; break; + } ret = ret * 10 + val; }