svn commit: r327618 - head/bin/cat
Warner Losh
imp at FreeBSD.org
Sat Jan 6 12:46:00 UTC 2018
Author: imp
Date: Sat Jan 6 12:45:59 2018
New Revision: 327618
URL: https://svnweb.freebsd.org/changeset/base/327618
Log:
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
Modified:
head/bin/cat/cat.c
Modified: head/bin/cat/cat.c
==============================================================================
--- head/bin/cat/cat.c Sat Jan 6 12:34:03 2018 (r327617)
+++ head/bin/cat/cat.c Sat Jan 6 12:45:59 2018 (r327618)
@@ -300,6 +300,7 @@ ilseq:
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");
}
More information about the svn-src-all
mailing list