add NULL pre firewall to ZVALUE code

The z*.c functions that take pointers that cannot be NULL are checked
for NULL pointers at the beginning of the function.

While calc is not known to pass bogus NULL pointers to ZVALUE related
code, libcalc could be called by external code that might do so by
mistake.  If that happens, math_error() is called with the name of
the function and the name of the arg that was NULL.
This commit is contained in:
Landon Curt Noll
2023-08-23 15:46:46 -07:00
parent 0bb66cff74
commit 61206172f1
8 changed files with 549 additions and 27 deletions

26
zmul.c
View File

@@ -148,6 +148,16 @@ domul(HALF *v1, LEN size1, HALF *v2, LEN size2, HALF *ans)
register HALF *hd, *h1=NULL, *h2=NULL; /* for inner loops */
SIUNION sival; /* for addition of digits */
/* firewall */
if (v1 == NULL) {
math_error("%s: v1 NULL", __func__);
not_reached();
}
if (ans == NULL) {
math_error("%s: ans NULL", __func__);
not_reached();
}
/*
* Trim the numbers of leading zeroes and initialize the
* estimated size of the result.
@@ -651,6 +661,12 @@ zsquare(ZVALUE z, ZVALUE *res)
{
LEN len;
/* firewall */
if (res == NULL) {
math_error("%s: res NULL", __func__);
not_reached();
}
if (ziszero(z)) {
*res = _zero_;
return;
@@ -735,6 +751,16 @@ dosquare(HALF *vp, LEN size, HALF *ans)
register HALF *hd, *h1, *h2, *h3; /* for inner loops */
SIUNION sival; /* for addition of digits */
/* firewall */
if (vp == NULL) {
math_error("%s: vp NULL", __func__);
not_reached();
}
if (ans == NULL) {
math_error("%s: ans NULL", __func__);
not_reached();
}
/*
* First trim the number of leading zeroes.
*/