Hi, I think this is probably the best course of action at this point.
I'll also need to move stat(1) to ubase as it is using major() and minor(). bye, sin
>From c3fdef5b71fa9f78ae9322d270428eb60584528d Mon Sep 17 00:00:00 2001 From: sin <s...@2f30.org> Date: Thu, 30 Jan 2014 14:51:21 +0000 Subject: [PATCH] Completely ignore character and block devices in tar(1) Support for character and block devices is optional in POSIX. We cannot guarantee that this will work correctly and it is not portable, so just drop support for it in tar(1). --- tar.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/tar.c b/tar.c index 1ecf8bd..dc82888 100644 --- a/tar.c +++ b/tar.c @@ -166,6 +166,13 @@ archive(const char* path) fprintf(stderr, "ignoring '%s'\n", path); return 0; } + mode = st.st_mode; + /* return early for character and block devices */ + if(S_ISCHR(mode) || S_ISBLK(mode)) { + weprintf("ignoring character or block device\n"); + return 0; + } + pw = getpwuid(st.st_uid); gr = getgrgid(st.st_gid); @@ -191,10 +198,6 @@ archive(const char* path) } else if(S_ISLNK(mode)) { h->type = SYMLINK; readlink(path, h->link, (sizeof h->link)-1); - } else if(S_ISCHR(mode) || S_ISBLK(mode)) { - h->type = S_ISCHR(mode) ? CHARDEV : BLOCKDEV; - putoctal(h->major, (unsigned)major(st.st_dev), sizeof h->major); - putoctal(h->minor, (unsigned)minor(st.st_dev), sizeof h->minor); } else if(S_ISFIFO(mode)) { h->type = FIFO; } @@ -221,7 +224,7 @@ unarchive(char *fname, int l, char b[Blksiz]) { char lname[101]; FILE *f = NULL; - unsigned long mode, major, minor, type; + unsigned long mode; Header *h = (void*)b; unlink(fname); @@ -244,15 +247,8 @@ unarchive(char *fname, int l, char b[Blksiz]) break; case CHARDEV: case BLOCKDEV: -#ifdef makedev - mode = strtoul(h->mode, 0, 8); - major = strtoul(h->major, 0, 8); - minor = strtoul(h->mode, 0, 8); - type = (h->type == CHARDEV) ? S_IFCHR : S_IFBLK; - if(mknod(fname, type | mode, makedev(major, minor))) - perror(fname); -#endif - break; + weprintf("ignoring character or block device\n"); + goto out; case FIFO: mode = strtoul(h->mode, 0, 8); if(mknod(fname, S_IFIFO | mode, 0)) @@ -265,6 +261,7 @@ unarchive(char *fname, int l, char b[Blksiz]) strtoul(h->gid, 0, 8))) perror(fname); +out: for(; l > 0; l -= Blksiz) { fread(b, Blksiz, 1, tarfile); if(f) -- 1.8.5.3