Skip to content

Commit

Permalink
add some I/O nullity protections
Browse files Browse the repository at this point in the history
  • Loading branch information
brlcad committed Feb 2, 2025
1 parent 0876097 commit d8c53d6
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/sig/dmod.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ get_args(int argc, char *argv[])
} else {
static char *file_name = NULL;
file_name = argv[bu_optind];
if ((infp = fopen(file_name, "rb")) == NULL) {
infp = fopen(file_name, "rb");
if (!infp) {
fprintf(stderr,
"%s: cannot open \"%s\" for reading\n",
progname, file_name);
Expand All @@ -136,16 +137,28 @@ main(int argc, char *argv[])
int j;
size_t ret;

int infpfd = 1; /* default stdin */
int soutfd = 0; /* default stdout */

double buf[BU_PAGE_SIZE] = {0.0}; /* working buffer */

bu_setprogname(argv[0]);

if (!get_args(argc, argv) || isatty(fileno(infp))
|| isatty(fileno(stdout))) {
if (infp)
infpfd = fileno(infp);
if (stdout)
soutfd = fileno(stdout);

if (!get_args(argc, argv)
|| !infp
|| !stdout
|| isatty(infpfd)
|| isatty(soutfd))
{
bu_exit(1, "%s", usage);
}

setmode(fileno(stdout), O_BINARY);
setmode(soutfd, O_BINARY);

while ((n = fread(buf, sizeof(*buf), BU_PAGE_SIZE, infp)) > 0) {
for (i = 0; i < numop; i++) {
Expand Down

0 comments on commit d8c53d6

Please sign in to comment.