summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorOtto Moerbeek <otto@cvs.openbsd.org>2006-01-19 20:06:56 +0000
committerOtto Moerbeek <otto@cvs.openbsd.org>2006-01-19 20:06:56 +0000
commit008a8ae030723e787f224149eb9ca4377ff8c254 (patch)
tree88c7740cfafa065b108b3a1a4215b80e4f5d9cc5 /usr.bin
parent9649a082319603e5abd5c1079346ef8abb1a0456 (diff)
delint: check value against UINT_MAX before casting to u_int; while
there fix a buglet in bexp(): x * UINT_MAX only overflows if x > 0
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/dc/bcode.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/usr.bin/dc/bcode.c b/usr.bin/dc/bcode.c
index d658853a304..10a997a09c6 100644
--- a/usr.bin/dc/bcode.c
+++ b/usr.bin/dc/bcode.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bcode.c,v 1.33 2006/01/16 08:09:25 otto Exp $ */
+/* $OpenBSD: bcode.c,v 1.34 2006/01/19 20:06:55 otto Exp $ */
/*
* Copyright (c) 2003, Otto Moerbeek <otto@drijf.net>
@@ -17,7 +17,7 @@
*/
#ifndef lint
-static const char rcsid[] = "$OpenBSD: bcode.c,v 1.33 2006/01/16 08:09:25 otto Exp $";
+static const char rcsid[] = "$OpenBSD: bcode.c,v 1.34 2006/01/19 20:06:55 otto Exp $";
#endif /* not lint */
#include <ssl/ssl.h>
@@ -577,8 +577,8 @@ set_scale(void)
warnx("scale must be a nonnegative number");
else {
scale = get_ulong(n);
- if (scale != BN_MASK2)
- bmachine.scale = scale;
+ if (scale != BN_MASK2 && scale <= UINT_MAX)
+ bmachine.scale = (u_int)scale;
else
warnx("scale too large");
}
@@ -605,8 +605,8 @@ set_obase(void)
n = pop_number();
if (n != NULL) {
base = get_ulong(n);
- if (base != BN_MASK2 && base > 1)
- bmachine.obase = base;
+ if (base != BN_MASK2 && base > 1 && base <= UINT_MAX)
+ bmachine.obase = (u_int)base;
else
warnx("output base must be a number greater than 1");
free_number(n);
@@ -633,7 +633,7 @@ set_ibase(void)
if (n != NULL) {
base = get_ulong(n);
if (base != BN_MASK2 && 2 <= base && base <= 16)
- bmachine.ibase = base;
+ bmachine.ibase = (u_int)base;
else
warnx("input base must be a number between 2 and 16 "
"(inclusive)");
@@ -707,7 +707,7 @@ static void
num_digits(void)
{
struct value *value;
- u_int digits;
+ size_t digits;
struct number *n = NULL;
value = pop();
@@ -1196,8 +1196,9 @@ bexp(void)
b = BN_get_word(p->number);
m = max(a->scale, bmachine.scale);
- scale = a->scale * b;
- if (scale > m || b == BN_MASK2)
+ scale = a->scale * (u_int)b;
+ if (scale > m || (a->scale > 0 && (b == BN_MASK2 ||
+ b > UINT_MAX)))
scale = m;
}