diff options
author | 2017-03-15 05:25:56 +0000 | |
---|---|---|
committer | 2017-03-15 05:25:56 +0000 | |
commit | 85e15f6fe704e90d6306099b5e9e8471d6b4906e (patch) | |
tree | 873d7ff94b5c1099c6988aa31e9bb8fa0101d66d /lib/libutil | |
parent | Add tests for scaled overflow and underflow and the exact overflow and (diff) | |
download | wireguard-openbsd-85e15f6fe704e90d6306099b5e9e8471d6b4906e.tar.xz wireguard-openbsd-85e15f6fe704e90d6306099b5e9e8471d6b4906e.zip |
Collapse underflow and overflow checks into a single block.
ok djm@ millert@
Diffstat (limited to 'lib/libutil')
-rw-r--r-- | lib/libutil/fmt_scaled.c | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/lib/libutil/fmt_scaled.c b/lib/libutil/fmt_scaled.c index 76085153752..f43b77d5c3b 100644 --- a/lib/libutil/fmt_scaled.c +++ b/lib/libutil/fmt_scaled.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fmt_scaled.c,v 1.14 2017/03/15 00:13:18 dtucker Exp $ */ +/* $OpenBSD: fmt_scaled.c,v 1.15 2017/03/15 05:25:56 dtucker Exp $ */ /* * Copyright (c) 2001, 2002, 2003 Ian F. Darwin. All rights reserved. @@ -166,12 +166,9 @@ scan_scaled(char *scaled, long long *result) } scale_fact = scale_factors[i]; - if (whole >= LLONG_MAX / scale_fact) { - errno = ERANGE; - return -1; - } - - if (whole <= LLONG_MIN / scale_fact) { + /* check for overflow and underflow after scaling */ + if (whole > LLONG_MAX / scale_fact || + whole < LLONG_MIN / scale_fact) { errno = ERANGE; return -1; } |