Date: Sat, 6 Jan 2018 12:45:59 +0000 (UTC) From: Warner Losh <imp@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r327618 - head/bin/cat Message-ID: <201801061245.w06Cjxmx033495@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
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"); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201801061245.w06Cjxmx033495>