[hackers] [sbase] Use strtol() instead of strtoul() in tar(1) || sin

From: <git_AT_suckless.org>
Date: Mon, 20 Apr 2015 17:36:12 +0200 (CEST)

commit 71eeb21feb2394c743daa8047394cbda813c522a
Author: sin <sin_AT_2f30.org>
Date: Mon Apr 20 16:33:24 2015 +0100

    Use strtol() instead of strtoul() in tar(1)

diff --git a/tar.c b/tar.c
index d680d46..f2d0a12 100644
--- a/tar.c
+++ b/tar.c
_AT_@ -205,8 +205,8 @@ unarchive(char *fname, ssize_t l, char b[BLKSIZ])
         long mode, major, minor, type, mtime, uid, gid;
         char lname[101], *tmp, *p;
 
- if (!mflag && ((mtime = strtoul(h->mtime, &p, 8)) < 0 || *p != '\0'))
- eprintf("strtoul %s: invalid number\n", h->mtime);
+ if (!mflag && ((mtime = strtol(h->mtime, &p, 8)) < 0 || *p != '\0'))
+ eprintf("strtol %s: invalid number\n", h->mtime);
         if (unlink(fname) < 0 && errno != ENOENT && errno != EISDIR)
                 eprintf("unlink %s:", fname);
 
_AT_@ -217,8 +217,8 @@ unarchive(char *fname, ssize_t l, char b[BLKSIZ])
         switch (h->type) {
         case REG:
         case AREG:
- if ((mode = strtoul(h->mode, &p, 8)) < 0 || *p != '\0')
- eprintf("strtoul %s: invalid number\n", h->mode);
+ if ((mode = strtol(h->mode, &p, 8)) < 0 || *p != '\0')
+ eprintf("strtol %s: invalid number\n", h->mode);
                 if (!(f = fopen(fname, "w")))
                         eprintf("fopen %s:", fname);
                 if (chmod(fname, mode) < 0)
_AT_@ -233,26 +233,26 @@ unarchive(char *fname, ssize_t l, char b[BLKSIZ])
                                 fname, lname);
                 break;
         case DIRECTORY:
- if ((mode = strtoul(h->mode, &p, 8)) < 0 || *p != '\0')
- eprintf("strtoul %s: invalid number\n", h->mode);
+ if ((mode = strtol(h->mode, &p, 8)) < 0 || *p != '\0')
+ eprintf("strtol %s: invalid number\n", h->mode);
                 if (mkdir(fname, (mode_t)mode) < 0 && errno != EEXIST)
                         eprintf("mkdir %s:", fname);
                 break;
         case CHARDEV:
         case BLOCKDEV:
- if ((mode = strtoul(h->mode, &p, 8)) < 0 || *p != '\0')
- eprintf("strtoul %s: invalid number\n", h->mode);
- if ((major = strtoul(h->major, &p, 8)) < 0 || *p != '\0')
- eprintf("strtoul %s: invalid number\n", h->major);
- if ((minor = strtoul(h->minor, &p, 8)) < 0 || *p != '\0')
- eprintf("strtoul %s: invalid number\n", h->minor);
+ if ((mode = strtol(h->mode, &p, 8)) < 0 || *p != '\0')
+ eprintf("strtol %s: invalid number\n", h->mode);
+ if ((major = strtol(h->major, &p, 8)) < 0 || *p != '\0')
+ eprintf("strtol %s: invalid number\n", h->major);
+ if ((minor = strtol(h->minor, &p, 8)) < 0 || *p != '\0')
+ eprintf("strtol %s: invalid number\n", h->minor);
                 type = (h->type == CHARDEV) ? S_IFCHR : S_IFBLK;
                 if (mknod(fname, type | mode, makedev(major, minor)) < 0)
                         eprintf("mknod %s:", fname);
                 break;
         case FIFO:
- if ((mode = strtoul(h->mode, &p, 8)) < 0 || *p != '\0')
- eprintf("strtoul %s: invalid number\n", h->mode);
+ if ((mode = strtol(h->mode, &p, 8)) < 0 || *p != '\0')
+ eprintf("strtol %s: invalid number\n", h->mode);
                 if (mknod(fname, S_IFIFO | mode, 0) < 0)
                         eprintf("mknod %s:", fname);
                 break;
_AT_@ -260,10 +260,10 @@ unarchive(char *fname, ssize_t l, char b[BLKSIZ])
                 eprintf("unsupported tar-filetype %c\n", h->type);
         }
 
- if ((uid = strtoul(h->uid, &p, 8)) < 0 || *p != '\0')
- eprintf("strtoul %s: invalid number\n", h->uid);
- if ((gid = strtoul(h->gid, &p, 8)) < 0 || *p != '\0')
- eprintf("strtoul %s: invalid number\n", h->gid);
+ if ((uid = strtol(h->uid, &p, 8)) < 0 || *p != '\0')
+ eprintf("strtol %s: invalid number\n", h->uid);
+ if ((gid = strtol(h->gid, &p, 8)) < 0 || *p != '\0')
+ eprintf("strtol %s: invalid number\n", h->gid);
         if (!getuid() && chown(fname, uid, gid))
                 eprintf("chown %s:", fname);
 
_AT_@ -351,8 +351,8 @@ xt(int (*fn)(char *, ssize_t, char[BLKSIZ]))
                         estrlcat(fname, "/", sizeof(fname));
                 }
                 estrlcat(fname, h->name, sizeof(fname));
- if ((size = strtoul(h->size, &p, 8)) < 0 || *p != '\0')
- eprintf("strtoul %s: invalid number\n", h->size);
+ if ((size = strtol(h->size, &p, 8)) < 0 || *p != '\0')
+ eprintf("strtol %s: invalid number\n", h->size);
 
                 fn(fname, size, b);
         }
Received on Mon Apr 20 2015 - 17:36:12 CEST

This archive was generated by hypermail 2.3.0 : Mon Apr 20 2015 - 17:48:15 CEST