mirror of
https://github.com/lcn2/calc.git
synced 2025-08-16 01:03:29 +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:
34
zio.c
34
zio.c
@@ -125,6 +125,12 @@ math_str(char *str)
|
||||
char *cp;
|
||||
size_t len;
|
||||
|
||||
/* firewall */
|
||||
if (str == NULL) {
|
||||
math_error("%s: str NULL", __func__);
|
||||
not_reached();
|
||||
}
|
||||
|
||||
if (!outputisstring) {
|
||||
fputs(str, outfp);
|
||||
return;
|
||||
@@ -155,6 +161,12 @@ math_str(char *str)
|
||||
void
|
||||
math_fill(char *str, long width)
|
||||
{
|
||||
/* firewall */
|
||||
if (str == NULL) {
|
||||
math_error("%s: str NULL", __func__);
|
||||
not_reached();
|
||||
}
|
||||
|
||||
if (width > 0) {
|
||||
width -= (long)strlen(str);
|
||||
while (width-- > 0)
|
||||
@@ -179,6 +191,12 @@ math_fmt(char *fmt, ...)
|
||||
va_list ap;
|
||||
char buf[BUFSIZ+1];
|
||||
|
||||
/* firewall */
|
||||
if (fmt == NULL) {
|
||||
math_error("%s: fmt NULL", __func__);
|
||||
not_reached();
|
||||
}
|
||||
|
||||
va_start(ap, fmt);
|
||||
vsnprintf(buf, BUFSIZ, fmt, ap);
|
||||
va_end(ap);
|
||||
@@ -295,6 +313,12 @@ math_cleardiversions(void)
|
||||
void
|
||||
math_setfp(FILE *newfp)
|
||||
{
|
||||
/* firewall */
|
||||
if (newfp == NULL) {
|
||||
math_error("%s: newfp NULL", __func__);
|
||||
not_reached();
|
||||
}
|
||||
|
||||
outfp = newfp;
|
||||
outputisstring = (oldiostates && (newfp == stdout));
|
||||
}
|
||||
@@ -714,6 +738,16 @@ str2z(char *s, ZVALUE *res)
|
||||
bool minus;
|
||||
long shift;
|
||||
|
||||
/* firewall */
|
||||
if (s == NULL) {
|
||||
math_error("%s: s NULL", __func__);
|
||||
not_reached();
|
||||
}
|
||||
if (res == NULL) {
|
||||
math_error("%s: res NULL", __func__);
|
||||
not_reached();
|
||||
}
|
||||
|
||||
minus = false;
|
||||
shift = 0;
|
||||
if (*s == '+')
|
||||
|
Reference in New Issue
Block a user