mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-06 23:27:04 +02:00
[BUG] fix error checking in strl2ic/strl2uic()
The strl2ic() and strl2uic() primitives used to convert string to integers could return 10 times the value read if they stopped on non-digit because of a mis-placed loop exit.
This commit is contained in:
parent
85130941e7
commit
3f0c976135
@ -152,14 +152,14 @@ static inline unsigned int __strl2ui(const char *s, int len)
|
|||||||
static inline unsigned int __strl2uic(const char *s, int len)
|
static inline unsigned int __strl2uic(const char *s, int len)
|
||||||
{
|
{
|
||||||
unsigned int i = 0;
|
unsigned int i = 0;
|
||||||
unsigned int j;
|
unsigned int j, k;
|
||||||
|
|
||||||
while (len-- > 0) {
|
while (len-- > 0) {
|
||||||
j = (*s++) - '0';
|
j = (*s++) - '0';
|
||||||
i = i * 10;
|
k = i * 10;
|
||||||
if (j > 9)
|
if (j > 9)
|
||||||
break;
|
break;
|
||||||
i += j;
|
i = k + j;
|
||||||
}
|
}
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
@ -248,27 +248,27 @@ unsigned int strl2uic(const char *s, int len)
|
|||||||
int strl2ic(const char *s, int len)
|
int strl2ic(const char *s, int len)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int j;
|
int j, k;
|
||||||
|
|
||||||
if (len > 0) {
|
if (len > 0) {
|
||||||
if (*s != '-') {
|
if (*s != '-') {
|
||||||
/* positive number */
|
/* positive number */
|
||||||
while (len-- > 0) {
|
while (len-- > 0) {
|
||||||
j = (*s++) - '0';
|
j = (*s++) - '0';
|
||||||
i = i * 10;
|
k = i * 10;
|
||||||
if (j > 9)
|
if (j > 9)
|
||||||
break;
|
break;
|
||||||
i += j;
|
i = k + j;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* negative number */
|
/* negative number */
|
||||||
s++;
|
s++;
|
||||||
while (--len > 0) {
|
while (--len > 0) {
|
||||||
j = (*s++) - '0';
|
j = (*s++) - '0';
|
||||||
i = i * 10;
|
k = i * 10;
|
||||||
if (j > 9)
|
if (j > 9)
|
||||||
break;
|
break;
|
||||||
i -= j;
|
i = k - j;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user