Sanity check sysconf return value to ensure it's positive before we

use it. Use proper cast to convert long to size_t (instead of
blksize_t) to preclude sign extension issues.

CID: 1193754
This commit is contained in:
Warner Losh 2018-01-06 12:45:59 +00:00
parent 1723a6e523
commit ca23e64eb4

View File

@ -300,6 +300,7 @@ cook_cat(FILE *fp)
static void
raw_cat(int rfd)
{
long pagesize;
int off, wfd;
ssize_t nr, nw;
static size_t bsize;
@ -316,9 +317,12 @@ raw_cat(int rfd)
bsize = MIN(BUFSIZE_MAX, MAXPHYS * 8);
else
bsize = BUFSIZE_SMALL;
} else
bsize = MAX(sbuf.st_blksize,
(blksize_t)sysconf(_SC_PAGESIZE));
} else {
bsize = sbuf.st_blksize;
pagesize = sysconf(_SC_PAGESIZE);
if (pagesize > 0)
bsize = MAX(bsize, (size_t)pagesize);
}
if ((buf = malloc(bsize)) == NULL)
err(1, "malloc() failure of IO buffer");
}