summaryrefslogtreecommitdiff
path: root/lib/libutil
diff options
context:
space:
mode:
authorDarren Tucker <dtucker@cvs.openbsd.org>2022-03-11 07:29:54 +0000
committerDarren Tucker <dtucker@cvs.openbsd.org>2022-03-11 07:29:54 +0000
commit2a73b9f2b7c251d637e8a3869f52ee406829439f (patch)
tree3d4758cb9c426b69b526d159def0253f82f7d051 /lib/libutil
parent39f9e8855b8f33fff69adaf8e01c68d9075314fd (diff)
Check for underflow as well as overflow when scaling negative numbers.
ok millert@
Diffstat (limited to 'lib/libutil')
-rw-r--r--lib/libutil/fmt_scaled.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/lib/libutil/fmt_scaled.c b/lib/libutil/fmt_scaled.c
index f06c727be51..0b443d4d83a 100644
--- a/lib/libutil/fmt_scaled.c
+++ b/lib/libutil/fmt_scaled.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fmt_scaled.c,v 1.20 2021/06/20 14:08:42 tb Exp $ */
+/* $OpenBSD: fmt_scaled.c,v 1.21 2022/03/11 07:29:53 dtucker Exp $ */
/*
* Copyright (c) 2001, 2002, 2003 Ian F. Darwin. All rights reserved.
@@ -185,7 +185,8 @@ scan_scaled(char *scaled, long long *result)
/* truncate fpart so it does't overflow.
* then scale fractional part.
*/
- while (fpart >= LLONG_MAX / scale_fact) {
+ while (fpart >= LLONG_MAX / scale_fact ||
+ fpart <= LLONG_MIN / scale_fact) {
fpart /= 10;
fract_digits--;
}