[net.bugs] Bug in System V tar

laman@sdcsvax.UUCP (11/18/83)

There is a bug in the System V "tar" source distribution.  If the user
creates a tape with a blocking factor of one (1) 512 bytes block per record,
tar gets stuck in an infinite loop when the user executes the following:

% tar tvf /dev/rmt0

or

% tar tvbf 1 /dev/rmt0

but the following work:

% tar tvfb /dev/rmt0 1

or

% tar tv0

(Tar also gets lost when extractions are attempted in the same manor.)

The problem is that in the 'f' case in the argument processing, "tar" can't
tell the difference between "nblock"'s initial value, and a value
specified with the 'b' option.  When a blocking factor of one (1) is specified,
it looks just like the initial value given to "nblock", so when "nblock"'s
value is zeroed (when it was one (1)) in the 'f' case , the user's
specified value is lost.  If the program is extracting, garbage is put into
the file.

The fix is to declare a "bflag" variable (initially set to zero), set it to one
when the 'b' option is processed, and modify the "if" statement comparing
"nblock" to one in the code that processes the 'f' option to require "bflag"
to be off (If it's on, then we know we have gotten the blocking factor).

39c39
< int	rflag, xflag, vflag, tflag, mt, cflag, mflag, bflag;
---
> int	rflag, xflag, vflag, tflag, mt, cflag, mflag;
74c74
< 			if (nblock == 1 && !bflag)
---
> 			if (nblock == 1)
126d125
< 			bflag = 1;

			Mike Laman
			UUCP: {ucbvax,philabs,sdccsu3,sdcsla}!sdcsvax!laman