mirror of
https://github.com/lcn2/calc.git
synced 2025-08-19 01:13:27 +03:00
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:
30
zprime.c
30
zprime.c
@@ -547,6 +547,12 @@ zfactor(ZVALUE n, ZVALUE zlimit, ZVALUE *res)
|
||||
{
|
||||
FULL f; /* factor found, or 0 */
|
||||
|
||||
/* firewall */
|
||||
if (res == NULL) {
|
||||
math_error("%s: res NULL", __func__);
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/*
|
||||
* determine the limit
|
||||
*/
|
||||
@@ -828,6 +834,12 @@ zpfact(ZVALUE z, ZVALUE *dest)
|
||||
CONST unsigned char *j; /* current jump increment */
|
||||
ZVALUE res, temp;
|
||||
|
||||
/* firewall */
|
||||
if (dest == NULL) {
|
||||
math_error("%s: dest NULL", __func__);
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/* firewall */
|
||||
if (zisneg(z)) {
|
||||
math_error("Negative argument for factorial");
|
||||
@@ -1212,6 +1224,12 @@ znextcand(ZVALUE z, long count, ZVALUE skip, ZVALUE res, ZVALUE mod,
|
||||
ZVALUE tmp1;
|
||||
ZVALUE tmp2;
|
||||
|
||||
/* firewall */
|
||||
if (cand == NULL) {
|
||||
math_error("%s: cand NULL", __func__);
|
||||
not_reached();
|
||||
}
|
||||
|
||||
z.sign = 0;
|
||||
mod.sign = 0;
|
||||
if (ziszero(mod)) {
|
||||
@@ -1292,6 +1310,12 @@ zprevcand(ZVALUE z, long count, ZVALUE skip, ZVALUE res, ZVALUE mod,
|
||||
ZVALUE tmp1;
|
||||
ZVALUE tmp2;
|
||||
|
||||
/* firewall */
|
||||
if (cand == NULL) {
|
||||
math_error("%s: cand NULL", __func__);
|
||||
not_reached();
|
||||
}
|
||||
|
||||
z.sign = 0;
|
||||
mod.sign = 0;
|
||||
if (ziszero(mod)) {
|
||||
@@ -1533,6 +1557,12 @@ zlcmfact(ZVALUE z, ZVALUE *dest)
|
||||
CONST unsigned short *pr; /* pointer to a small prime */
|
||||
ZVALUE res, temp;
|
||||
|
||||
/* firewall */
|
||||
if (dest == NULL) {
|
||||
math_error("%s: dest NULL", __func__);
|
||||
not_reached();
|
||||
}
|
||||
|
||||
if (zisneg(z) || ziszero(z)) {
|
||||
math_error("Non-positive argument for lcmfact");
|
||||
not_reached();
|
||||
|
Reference in New Issue
Block a user