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:
parent
1723a6e523
commit
ca23e64eb4
@ -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");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user