mkports

recipes for building multiple softwares with mk(1)
git clone git://z3bra.org/mkports
Log | Files | Refs

commit aafc389decda0d3a3aba8a1d01cf99f97d3b8952
parent 1f4c68cf6443f28efa46fc98bfd6c46c34f2862a
Author: z3bra <contactatz3bradotorg>
Date:   Fri Feb  3 18:19:11 +0100

sbase: patches to fix tar bug

Diffstat:
sbase/patches/sbase-tarformaterrors-20170203-3bc2ffc.diff | 72++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
sbase/patches/sbase-tarreadall-20170203-3bc2ffc.diff | 29+++++++++++++++++++++++++++++
2 files changed, 101 insertions(+), 0 deletions(-)
diff --git a/sbase/patches/sbase-tarformaterrors-20170203-3bc2ffc.diff b/sbase/patches/sbase-tarformaterrors-20170203-3bc2ffc.diff @@ -0,0 +1,72 @@ +diff --git a/tar.c b/tar.c +index 71719b0..4a81f8f 100644 +--- a/tar.c ++++ b/tar.c +@@ -29,6 +29,12 @@ enum Type { + RESERVED = '7' + }; + ++enum Error { ++ BADCHKSUM, ++ BADMAGIC, ++ BADPATH ++}; ++ + struct header { + char name[100]; + char mode[8]; +@@ -71,6 +77,12 @@ static const char *filtertools[] = { + ['z'] = "gzip", + }; + ++static const char *errors[] = { ++ [BADCHKSUM] = "bad checksum", ++ [BADMAGIC] = "bad magic", ++ [BADPATH] = "empty filename" ++}; ++ + static void + pushdirtime(char *name, time_t mtime) + { +@@ -407,27 +419,36 @@ chktar(struct header *h) + char tmp[8], *err; + char *p = (char *)h; + long s1, s2, i; ++ int errnum; + +- if (h->prefix[0] == '\0' && h->name[0] == '\0') ++ if (h->prefix[0] == '\0' && h->name[0] == '\0') { ++ errnum = BADPATH; + goto bad; +- if (h->magic[0] && strncmp("ustar", h->magic, 5)) ++ } ++ if (h->magic[0] && strncmp("ustar", h->magic, 5)) { ++ errnum = BADMAGIC; + goto bad; ++ } + memcpy(tmp, h->chksum, sizeof(tmp)); + for (i = 0; i < sizeof(tmp); i++) + if (tmp[i] == ' ') + tmp[i] = '\0'; + s1 = strtol(tmp, &err, 8); +- if (s1 < 0 || *err != '\0') ++ if (s1 < 0 || *err != '\0') { ++ errnum = BADCHKSUM; + goto bad; ++ } + memset(h->chksum, ' ', sizeof(h->chksum)); + for (i = 0, s2 = 0; i < sizeof(*h); i++) + s2 += (unsigned char)p[i]; +- if (s1 != s2) ++ if (s1 != s2) { ++ errnum = BADCHKSUM; + goto bad; ++ } + memcpy(h->chksum, tmp, sizeof(h->chksum)); + return; + bad: +- eprintf("malformed tar archive\n"); ++ eprintf("malformed tar archive: %s\n", errors[errnum]); + } + + static void diff --git a/sbase/patches/sbase-tarreadall-20170203-3bc2ffc.diff b/sbase/patches/sbase-tarreadall-20170203-3bc2ffc.diff @@ -0,0 +1,29 @@ +diff --git a/tar.c b/tar.c +index 4a81f8f..f2649f1 100644 +--- a/tar.c ++++ b/tar.c +@@ -155,16 +155,21 @@ decomp(int fd, const char *tool, const char *flags) + static ssize_t + eread(int fd, void *buf, size_t n) + { +- ssize_t r; ++ char *tmp = buf; ++ ssize_t r, s = 0; + + again: +- r = read(fd, buf, n); ++ r = read(fd, tmp + s, n - s); ++ s += r; + if (r < 0) { + if (errno == EINTR) + goto again; + eprintf("read:"); + } +- return r; ++ if (s < n) ++ goto again; ++ ++ return s; + } + + static ssize_t