From owner-svn-src-head@FreeBSD.ORG Mon Oct 27 16:03:59 2014 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id C0ED67A3; Mon, 27 Oct 2014 16:03:59 +0000 (UTC) Received: from mail105.syd.optusnet.com.au (mail105.syd.optusnet.com.au [211.29.132.249]) by mx1.freebsd.org (Postfix) with ESMTP id 820B7BBC; Mon, 27 Oct 2014 16:03:59 +0000 (UTC) Received: from c122-106-147-133.carlnfd1.nsw.optusnet.com.au (c122-106-147-133.carlnfd1.nsw.optusnet.com.au [122.106.147.133]) by mail105.syd.optusnet.com.au (Postfix) with ESMTPS id DA5CD1043210; Tue, 28 Oct 2014 03:03:57 +1100 (AEDT) Date: Tue, 28 Oct 2014 03:03:57 +1100 (EST) From: Bruce Evans X-X-Sender: bde@besplex.bde.org To: Konstantin Belousov Subject: Re: svn commit: r273734 - head/bin/dd In-Reply-To: <20141027153957.GZ1877@kib.kiev.ua> Message-ID: <20141028024954.L2501@besplex.bde.org> References: <201410271138.s9RBcHrA002447@svn.freebsd.org> <20141027153957.GZ1877@kib.kiev.ua> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Optus-CM-Score: 0 X-Optus-CM-Analysis: v=2.1 cv=dMCfxopb c=1 sm=1 tr=0 a=7NqvjVvQucbO2RlWB8PEog==:117 a=PO7r1zJSAAAA:8 a=kj9zAlcOel0A:10 a=JzwRw_2MAAAA:8 a=RjzIgjlDYm5_AU5-cgkA:9 a=vx3u5fnQNF83gsCp:21 a=_J6P8AWba1TwnPjU:21 a=CjuIK1q_8ugA:10 Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org, Kurt Jaeger X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 27 Oct 2014 16:03:59 -0000 On Mon, 27 Oct 2014, Konstantin Belousov wrote: > On Mon, Oct 27, 2014 at 11:38:17AM +0000, Kurt Jaeger wrote: >> Log: >> bin/dd: Fix incorrect casting of arguments > This causes non-trivial amount of errors like > > cc1: warnings being treated as errors > /scratch/tmp/kib/src/bin/dd/args.c: In function 'f_bs': > /scratch/tmp/kib/src/bin/dd/args.c:192: warning: format '%jd' expects type 'intm > ax_t', but argument 3 has type 'int' > > (this is on arm). Sigh. I noticed that half the changes were to break correct casting, but thought that the errors were not detected on any supported arch (since the patch wouldn't have passed review if they were). Actually, they are detected on all 32-bit arches (since 32-bit SSIZE_MAX is incompatible with 64-bit intmax_t). Further examination of the history: in green's big patch that fixed most of the arg checking, or at least in its MFC, there is this breakage: % Index: args.c % =================================================================== % RCS file: /home/ncvs/src/bin/dd/args.c,v % retrieving revision 1.13.2.2 % retrieving revision 1.13.2.3 % diff -u -2 -r1.13.2.2 -r1.13.2.3 % --- args.c 29 Aug 1999 14:12:07 -0000 1.13.2.2 % +++ args.c 12 Dec 1999 01:54:03 -0000 1.13.2.3 % ... % @@ -207,7 +208,9 @@ % { % % - cpy_cnt = (u_int)get_bsz(arg); % - if (!cpy_cnt) % - terminate(0); % + cpy_cnt = get_num(arg); % + if (cpy_cnt < 0) % + errx(1, "count cannot be negative"); % + if (cpy_cnt == 0) % + cpy_cnt = -1; % } % % @@ -217,5 +220,7 @@ % { % % - files_cnt = (int)get_bsz(arg); % + files_cnt = get_num(arg); % + if (files_cnt < 1) % + errx(1, "files must be between 1 and %qd", QUAD_MAX); % } % The magic -1 wasn't in previous versions. It is just some hack to recover the previous behaviour. My version doesn't have it, but uses essentially the old code with no range checking but the type expanded to uintmax_t. All uintmax_t values are valid counts. The correct range checking is already in get_num(). I also removed the special case for cpuy_cnt = 0. I think it means no limit in my version. This is more useful than immediate termination. Bruce