← Commit list

416914fc6

Denis Vlasenko
Denis Vlasenko
2008-07-17
FAILED Duration: 25s

Subject

bb_strtoXXX: close bug 4174 (potential use of buf[-1])

Binary

No binary (build failed)

Architecture & Compiler Flags

Architecture: x86_64-linux-gnu Compiler: gcc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0

—

Build Log

(log yok)

Commit Diff GitHub →

libbb/bb_strtonum.c+5 -6
@@ -30,12 +30,6 @@ static unsigned long long handle_errors(unsigned long long v, char **endp, char
{
if (endp) *endp = endptr;
- /* Check for the weird "feature":
- * a "-" string is apparently a valid "number" for strto[u]l[l]!
- * It returns zero and errno is 0! :( */
- if (endptr[-1] == '-')
- return ret_ERANGE();
-
/* errno is already set to ERANGE by strtoXXX if value overflowed */
if (endptr[0]) {
/* "1234abcg" or out-of-range? */
@@ -44,6 +38,11 @@ static unsigned long long handle_errors(unsigned long long v, char **endp, char
/* good number, just suspicious terminator */
errno = EINVAL;
}
+ /* Check for the weird "feature":
+ * a "-" string is apparently a valid "number" for strto[u]l[l]!
+ * It returns zero and errno is 0! :( */
+ if (endptr[-1] == '-')
+ return ret_ERANGE();
return v;
}