[Toybox] [PATCH] cpio: fix -it
Isaac Dunham
ibid.ag at gmail.com
Wed Mar 26 10:13:07 PDT 2014
Fix cpio -it: don't close(fd) unless we opened it.
--
On Wed, Mar 26, 2014 at 06:16:30AM -0500, Rob Landley wrote:
> On 03/26/14 01:30, Isaac Dunham wrote:
> > * nlen is equal to len+1, and must always be set after getline() and
> > further processing. (Using len++ instead may be better, long-term.)
> > Fixes a segfault.
>
> Let's see, if somebody feeds us a name with an embedded NUL byte through
> the stdin file list, we write the longer name into the archive, but the
> filesystem happily stops at the NUL on all the system calls, so it
> shouldn't matter than we're passing around the larger buffer...
>
> So other than the potential for steganography, not a big deal.
I had to move it there, and then decided it was pointless to use strlen
when we had the length already.
> > * Check nlen instead of llen when padding is 4 - (namelen % 4)
>
> I think I already got that one from your previous patch? (I didn't get
> to rsync yesterday's commits until just now.)
Yup. I made that change again against the older cpio code because that's
what was available and I couldn't get cpio -o working without it.
HTH,
Isaac Dunham
-------------- next part --------------
diff --git a/toys/posix/cpio.c b/toys/posix/cpio.c
index 4817403..8263de3 100644
--- a/toys/posix/cpio.c
+++ b/toys/posix/cpio.c
@@ -141,7 +141,7 @@ void cpio_main(void)
}
size -= sizeof(toybuf);
}
- close(fd);
+ if (!test) close(fd);
} else if (!test)
err = mknod(name, mode, makedev(x8u(toybuf+62), x8u(toybuf+70)));
More information about the Toybox
mailing list