changeset 1230:c78ffc6c330a draft

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.
author Rob Landley <rob@landley.net>
date Wed, 26 Mar 2014 06:07:06 -0500
parents 34d4ee60e78f
children ee5a6875d695
files toys/posix/cpio.c
diffstat 1 files changed, 5 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/toys/posix/cpio.c	Tue Mar 25 07:35:56 2014 -0500
+++ b/toys/posix/cpio.c	Wed Mar 26 06:07:06 2014 -0500
@@ -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 @@
 
     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 @@
     }
     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);
   }
 }