Date: Sun, 21 Dec 2014 23:22:13 +0000 (UTC) From: Jilles Tjoelker <jilles@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org Subject: svn commit: r276041 - stable/9/usr.bin/truncate Message-ID: <201412212322.sBLNMDDu035467@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: jilles Date: Sun Dec 21 23:22:12 2014 New Revision: 276041 URL: https://svnweb.freebsd.org/changeset/base/276041 Log: MFC r267265: truncate: Detect integer overflow, fix relative sizes. The change to expand_number (r204654) broke detection of too large sizes and relative sizes ('+'/'-'). There are no tests in the MFC because stable/9 lacks the test framework. PR: 190735 Submitted by: Kirk Russell Modified: stable/9/usr.bin/truncate/truncate.c Directory Properties: stable/9/usr.bin/truncate/ (props changed) Modified: stable/9/usr.bin/truncate/truncate.c ============================================================================== --- stable/9/usr.bin/truncate/truncate.c Sun Dec 21 23:22:11 2014 (r276040) +++ stable/9/usr.bin/truncate/truncate.c Sun Dec 21 23:22:12 2014 (r276041) @@ -54,8 +54,8 @@ main(int argc, char **argv) { struct stat sb; mode_t omode; - off_t oflow, rsize, tsize; - int64_t sz; + off_t oflow, rsize, sz, tsize; + uint64_t usz; int ch, error, fd, oflags; char *fname, *rname; @@ -73,11 +73,13 @@ main(int argc, char **argv) rname = optarg; break; case 's': - if (expand_number(optarg, &sz) == -1) + do_relative = *optarg == '+' || *optarg == '-'; + if (expand_number(do_relative ? optarg + 1 : optarg, + &usz) == -1 || (off_t)usz < 0) errx(EXIT_FAILURE, "invalid size argument `%s'", optarg); - if (*optarg == '+' || *optarg == '-') - do_relative = 1; + + sz = (*optarg == '-') ? -(off_t)usz : (off_t)usz; got_size = 1; break; default:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201412212322.sBLNMDDu035467>