1
0
mirror of https://github.com/openbsd/src.git synced 2026-04-29 16:47:15 +00:00

dc: error check BN_get_word() failure with (BN_ULONG)-1

ok deraadt
This commit is contained in:
tb
2025-12-15 12:10:46 +00:00
parent 4fef168773
commit f8d7bc5263

View File

@@ -1,4 +1,4 @@
/* $OpenBSD: bcode.c,v 1.64 2025/12/06 06:40:49 tb Exp $ */
/* $OpenBSD: bcode.c,v 1.65 2025/12/15 12:10:46 tb Exp $ */
/*
* Copyright (c) 2003, Otto Moerbeek <otto@drijf.net>
@@ -25,10 +25,6 @@
#include "extern.h"
#ifndef BN_MASK2
#define BN_MASK2 (BN_ULONG)-1
#endif
/* #define DEBUGGING */
#define MAX_ARRAY_INDEX 2048
@@ -591,7 +587,7 @@ set_scale(void)
warnx("scale must be a nonnegative number");
else {
scale = get_ulong(n);
if (scale != BN_MASK2 && scale <= UINT_MAX)
if (scale != (BN_ULONG)-1 && scale <= UINT_MAX)
bmachine.scale = (u_int)scale;
else
warnx("scale too large");
@@ -619,7 +615,7 @@ set_obase(void)
n = pop_number();
if (n != NULL) {
base = get_ulong(n);
if (base != BN_MASK2 && base > 1 && base <= UINT_MAX)
if (base != (BN_ULONG)-1 && base > 1 && base <= UINT_MAX)
bmachine.obase = (u_int)base;
else
warnx("output base must be a number greater than 1");
@@ -646,7 +642,7 @@ set_ibase(void)
n = pop_number();
if (n != NULL) {
base = get_ulong(n);
if (base != BN_MASK2 && 2 <= base && base <= 16)
if (base != (BN_ULONG)-1 && 2 <= base && base <= 16)
bmachine.ibase = (u_int)base;
else
warnx("input base must be a number between 2 and 16 "
@@ -911,7 +907,7 @@ load_array(void)
idx = get_ulong(inumber);
if (BN_is_negative(inumber->number))
warnx("negative idx");
else if (idx == BN_MASK2 || idx > MAX_ARRAY_INDEX)
else if (idx == (BN_ULONG)-1 || idx > MAX_ARRAY_INDEX)
warnx("idx too big");
else {
stack = &bmachine.reg[reg];
@@ -950,7 +946,7 @@ store_array(void)
if (BN_is_negative(inumber->number)) {
warnx("negative idx");
stack_free_value(value);
} else if (idx == BN_MASK2 || idx > MAX_ARRAY_INDEX) {
} else if (idx == (BN_ULONG)-1 || idx > MAX_ARRAY_INDEX) {
warnx("idx too big");
stack_free_value(value);
} else {
@@ -1200,7 +1196,7 @@ bexp(void)
b = BN_get_word(p->number);
m = max(a->scale, bmachine.scale);
rscale = a->scale * (u_int)b;
if (rscale > m || (a->scale > 0 && (b == BN_MASK2 ||
if (rscale > m || (a->scale > 0 && (b == (BN_ULONG)-1 ||
b > UINT_MAX)))
rscale = m;
}
@@ -1520,7 +1516,7 @@ quitN(void)
return;
i = get_ulong(n);
free_number(n);
if (i == BN_MASK2 || i == 0)
if (i == (BN_ULONG)-1 || i == 0)
warnx("Q command requires a number >= 1");
else if (bmachine.readsp < i)
warnx("Q command argument exceeded string execution depth");
@@ -1542,7 +1538,7 @@ skipN(void)
if (n == NULL)
return;
i = get_ulong(n);
if (i == BN_MASK2)
if (i == (BN_ULONG)-1)
warnx("J command requires a number >= 0");
else if (i > 0 && bmachine.readsp < i)
warnx("J command argument exceeded string execution depth");