svn commit: r273734 - head/bin/dd

Bruce Evans brde at optusnet.com.au
Mon Oct 27 16:03:59 UTC 2014


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


More information about the svn-src-head mailing list