Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 7 Dec 2014 22:30:55 +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-10@freebsd.org
Subject:   svn commit: r275585 - in stable/10: etc/mtree usr.bin/truncate usr.bin/truncate/tests
Message-ID:  <201412072230.sB7MUtZa065987@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jilles
Date: Sun Dec  7 22:30:54 2014
New Revision: 275585
URL: https://svnweb.freebsd.org/changeset/base/275585

Log:
  MFC r267265: truncate: Detect integer overflow, fix relative sizes, add tests.
  
  The change to expand_number (r204654) broke detection of too large sizes and
  relative sizes ('+'/'-').
  
  Also add some tests.
  
  The usr.bin/truncate/Makefile is slightly different in the MFC because
  src.opts.mk does not exist in stable/10.
  
  PR:		190735
  Submitted by:	Kirk Russell

Added:
  stable/10/usr.bin/truncate/tests/
     - copied from r267265, head/usr.bin/truncate/tests/
Modified:
  stable/10/etc/mtree/BSD.tests.dist
  stable/10/usr.bin/truncate/Makefile
  stable/10/usr.bin/truncate/truncate.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/etc/mtree/BSD.tests.dist
==============================================================================
--- stable/10/etc/mtree/BSD.tests.dist	Sun Dec  7 21:47:19 2014	(r275584)
+++ stable/10/etc/mtree/BSD.tests.dist	Sun Dec  7 22:30:54 2014	(r275585)
@@ -291,6 +291,8 @@
             ..
             tr
             ..
+            truncate
+            ..
             uudecode
             ..
             uuencode

Modified: stable/10/usr.bin/truncate/Makefile
==============================================================================
--- stable/10/usr.bin/truncate/Makefile	Sun Dec  7 21:47:19 2014	(r275584)
+++ stable/10/usr.bin/truncate/Makefile	Sun Dec  7 22:30:54 2014	(r275585)
@@ -1,7 +1,13 @@
 # $FreeBSD$
 
+.include <bsd.own.mk>
+
 PROG=		truncate
 DPADD=		${LIBUTIL}
 LDADD=		-lutil
 
+.if ${MK_TESTS} != "no"
+SUBDIR+= tests
+.endif
+
 .include <bsd.prog.mk>

Modified: stable/10/usr.bin/truncate/truncate.c
==============================================================================
--- stable/10/usr.bin/truncate/truncate.c	Sun Dec  7 21:47:19 2014	(r275584)
+++ stable/10/usr.bin/truncate/truncate.c	Sun Dec  7 22:30:54 2014	(r275585)
@@ -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?201412072230.sB7MUtZa065987>