From 392e12769fd41ede6b3e2685b5682275843a9b1d Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Wed, 26 Mar 2014 06:07:06 -0500 Subject: More cpio bugfixes from Isaac Dunham. Fix FLAG_o to actually be 1 like the comment says, don't try to strlen(name) before reading it, pad TRAILER!!! entry correctly. --- toys/posix/cpio.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'toys/posix/cpio.c') diff --git a/toys/posix/cpio.c b/toys/posix/cpio.c index 900e5128..4817403f 100644 --- a/toys/posix/cpio.c +++ b/toys/posix/cpio.c @@ -13,7 +13,7 @@ * In order: magic ino mode uid gid nlink mtime filesize devmajor devminor * rdevmajor rdevminor namesize check -USE_CPIO(NEWTOY(cpio, "duH:i|t|F:o|v(verbose)[!io][!ot]", TOYFLAG_BIN)) +USE_CPIO(NEWTOY(cpio, "duH:i|t|F:v(verbose)o|[!io][!ot]", TOYFLAG_BIN)) config CPIO bool "cpio" @@ -156,13 +156,14 @@ void cpio_main(void) for (;;) { struct stat st; - unsigned nlen = strlen(name)+1, error = 0, zero = 0; + unsigned nlen, error = 0, zero = 0; int len, fd = -1; ssize_t llen; len = getline(&name, &size, stdin); if (len<1) break; if (name[len-1] == '\n') name[--len] = 0; + nlen = len+1; if (lstat(name, &st) || (S_ISREG(st.st_mode) && (fd = open(name, O_RDONLY))<0)) { @@ -206,8 +207,8 @@ void cpio_main(void) } free(name); + memset(toybuf, 0, sizeof(toybuf)); xwrite(afd, toybuf, - sprintf(toybuf, "070701%040X%056X%08XTRAILER!!!%c%c%c", - 1, 0x0b, 0, 0, 0, 0)); + sprintf(toybuf, "070701%040X%056X%08XTRAILER!!!", 1, 0x0b, 0)+4); } } -- cgit v1.2.3