[Toybox] cpio: allow -it and fix two bugs in -o

ibid.ag at gmail.com ibid.ag at gmail.com
Sun Mar 16 17:35:43 PDT 2014


No infinite loop on EOF; archive devices; allow -it

getline(&name, &size, fd) will return -1 at EOF without setting
name to 0. Thus, the old check resulted in an infinite loop 
re-archiving the file.

Non-regular files are archived as size 0; whether we can open them
is irrelevant.
The test most exactly expressing the logic would be
if (lstat(...) || ((S_ISREG(...)) && (open(...)<0))
    //skip this file verbosely

But GCC thinks fd may be used uninitialized here, which is
technically half-correct; in the case of a non-regular file, 
fd would be passed to write_cpio_member uninitialized, and then ignored.
So instead, we ignore a failed open() on non-regular files.

SUSv2 says to use -it not -t; don't prevent it.

--
I discovered that there were a few bugs in the new archive creation code.
Besides the two this fixes, the padding is very much wrong.
I have not (yet) fixed that.

The comment got stuck in there because the check has gotten deleted
once, so it seems to not be obvious what it's doing.

I've started a test, but...it needs some more work.
A quick check is:
echo -e "/dev/null\n/dev/console"| cpio -o | cpio -it 

which should output: 
/dev/null
/dev/console

(the cpio you're testing must be in $PATH)

HTH,
Isaac Dunham



 1395016543.0


More information about the Toybox mailing list