aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-07-17 08:48:13 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-07-17 08:48:13 +0000
commit416914fc6115d2013433a5956febcffb5c8a0466 (patch)
tree09ba8bd4acad70e895bafc84623151cff4da3972
parent627052e75d6657a029a328cffd0832cb581b82fd (diff)
downloadbusybox-w32-416914fc6115d2013433a5956febcffb5c8a0466.tar.gz
busybox-w32-416914fc6115d2013433a5956febcffb5c8a0466.tar.bz2
busybox-w32-416914fc6115d2013433a5956febcffb5c8a0466.zip
bb_strtoXXX: close bug 4174 (potential use of buf[-1])
-rw-r--r--libbb/bb_strtonum.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/libbb/bb_strtonum.c b/libbb/bb_strtonum.c
index 50ed99b4b..2433f1f1f 100644
--- a/libbb/bb_strtonum.c
+++ b/libbb/bb_strtonum.c
@@ -30,12 +30,6 @@ static unsigned long long handle_errors(unsigned long long v, char **endp, char
30{ 30{
31 if (endp) *endp = endptr; 31 if (endp) *endp = endptr;
32 32
33 /* Check for the weird "feature":
34 * a "-" string is apparently a valid "number" for strto[u]l[l]!
35 * It returns zero and errno is 0! :( */
36 if (endptr[-1] == '-')
37 return ret_ERANGE();
38
39 /* errno is already set to ERANGE by strtoXXX if value overflowed */ 33 /* errno is already set to ERANGE by strtoXXX if value overflowed */
40 if (endptr[0]) { 34 if (endptr[0]) {
41 /* "1234abcg" or out-of-range? */ 35 /* "1234abcg" or out-of-range? */
@@ -44,6 +38,11 @@ static unsigned long long handle_errors(unsigned long long v, char **endp, char
44 /* good number, just suspicious terminator */ 38 /* good number, just suspicious terminator */
45 errno = EINVAL; 39 errno = EINVAL;
46 } 40 }
41 /* Check for the weird "feature":
42 * a "-" string is apparently a valid "number" for strto[u]l[l]!
43 * It returns zero and errno is 0! :( */
44 if (endptr[-1] == '-')
45 return ret_ERANGE();
47 return v; 46 return v;
48} 47}
49 48