svn commit: r276041 - stable/9/usr.bin/truncate
Jilles Tjoelker
jilles at FreeBSD.org
Sun Dec 21 23:22:14 UTC 2014
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:
More information about the svn-src-stable-9
mailing list