Skip to content

Commit be9dcdf

Browse files
author
Joao Gramacho
committed
Bug#16997513 MY_STRTOLL10 ACCEPTING OVERFLOWED UNSIGNED LONG LONG VALUES AS NORMAL ONES
Problem: ======= It was detected an incorrect behavior of my_strtoll10 function when converting strings with numbers in the following format: "184467440XXXXXXXXXYY" Where XXXXXXXXX > 737095516 and YY <= 15 Samples of problematic numbers: "18446744073709551915" "18446744073709552001" Instead of returning the larger unsigned long long value and setting overflow in the returned error code, my_strtoll10 function returns the lower 64-bits of the evaluated number and did not set overflow in the returned error code. Analysis: ======== Once trying to fix bug 16820156, I've found this bug in the overflow check of my_strtoll10 function. This function, once receiving a string with an integer number larger than 18446744073709551615 (the larger unsigned long long number) should return the larger unsigned long long number and set overflow in the returned error code. Because of a wrong overflow evaluation, the function didn't catch the overflow cases where (i == cutoff) && (j > cutoff2) && (k <= cutoff3). When the overflow evaluation fails, the function return the lower 64-bits of the evaluated number and do not set overflow in the returned error code. Fix: === Corrected the overflow evaluation in my_strtoll10.
1 parent d95e57a commit be9dcdf

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

strings/my_strtoll10.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,8 @@ longlong my_strtoll10(const char *nptr, char **endptr, int *error)
206206
goto overflow;
207207

208208
/* Check that we didn't get an overflow with the last digit */
209-
if (i > cutoff || (i == cutoff && ((j > cutoff2 || j == cutoff2) &&
210-
k > cutoff3)))
209+
if (i > cutoff || (i == cutoff && (j > cutoff2 || (j == cutoff2 &&
210+
k > cutoff3))))
211211
goto overflow;
212212
li=i*LFACTOR2+ (ulonglong) j*100 + k;
213213
return (longlong) li;

0 commit comments

Comments
 (0)