aboutsummaryrefslogtreecommitdiff
path: root/toys/pending
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2014-03-25 07:24:50 -0500
committerRob Landley <rob@landley.net>2014-03-25 07:24:50 -0500
commit6d796b61a6b9f7ea8c15f26db6dec7e0b9b486fd (patch)
tree46f29fd8c5b864bb250e2ac5f4bdc3ba987611f4 /toys/pending
parentdba5a37b9d1388bfd642d5404da6fce6849c5b1f (diff)
downloadtoybox-6d796b61a6b9f7ea8c15f26db6dec7e0b9b486fd.tar.gz
Several cpio bugfixes spotted by Isaac Dunham.
Diffstat (limited to 'toys/pending')
-rw-r--r--toys/pending/cpio.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/toys/pending/cpio.c b/toys/pending/cpio.c
index d1fd8a16..18877c1f 100644
--- a/toys/pending/cpio.c
+++ b/toys/pending/cpio.c
@@ -157,13 +157,15 @@ void cpio_main(void)
for (;;) {
struct stat st;
unsigned nlen = strlen(name)+1, error = 0, zero = 0;
- int len, fd;
+ int len, fd = -1;
ssize_t llen;
len = getline(&name, &size, stdin);
if (len<1) break;
if (name[len-1] == '\n') name[--len] = 0;
- if (lstat(name, &st) || (fd = open(name, O_RDONLY))<0) {
+ if (lstat(name, &st)
+ || (S_ISREG(st.st_mode) && (fd = open(name, O_RDONLY))<0))
+ {
perror_msg("%s", name);
continue;
}
@@ -191,13 +193,14 @@ void cpio_main(void)
else perror_msg("readlink '%s'", name);
} else while (llen) {
nlen = llen > sizeof(toybuf) ? sizeof(toybuf) : llen;
+ llen -= nlen;
// If read fails, write anyway (already wrote size in header)
if (nlen != readall(fd, toybuf, nlen))
if (!error++) perror_msg("bad read from file '%s'", name);
xwrite(afd, toybuf, nlen);
}
llen = st.st_size & 3;
- if (nlen) write(afd, &zero, 4-llen);
+ if (llen) write(afd, &zero, 4-llen);
}
close(fd);
}