Use strtol() instead of strtoul() in tar(1)
This commit is contained in:
parent
97905f6991
commit
71eeb21feb
40
tar.c
40
tar.c
|
@ -205,8 +205,8 @@ unarchive(char *fname, ssize_t l, char b[BLKSIZ])
|
||||||
long mode, major, minor, type, mtime, uid, gid;
|
long mode, major, minor, type, mtime, uid, gid;
|
||||||
char lname[101], *tmp, *p;
|
char lname[101], *tmp, *p;
|
||||||
|
|
||||||
if (!mflag && ((mtime = strtoul(h->mtime, &p, 8)) < 0 || *p != '\0'))
|
if (!mflag && ((mtime = strtol(h->mtime, &p, 8)) < 0 || *p != '\0'))
|
||||||
eprintf("strtoul %s: invalid number\n", h->mtime);
|
eprintf("strtol %s: invalid number\n", h->mtime);
|
||||||
if (unlink(fname) < 0 && errno != ENOENT && errno != EISDIR)
|
if (unlink(fname) < 0 && errno != ENOENT && errno != EISDIR)
|
||||||
eprintf("unlink %s:", fname);
|
eprintf("unlink %s:", fname);
|
||||||
|
|
||||||
|
@ -217,8 +217,8 @@ unarchive(char *fname, ssize_t l, char b[BLKSIZ])
|
||||||
switch (h->type) {
|
switch (h->type) {
|
||||||
case REG:
|
case REG:
|
||||||
case AREG:
|
case AREG:
|
||||||
if ((mode = strtoul(h->mode, &p, 8)) < 0 || *p != '\0')
|
if ((mode = strtol(h->mode, &p, 8)) < 0 || *p != '\0')
|
||||||
eprintf("strtoul %s: invalid number\n", h->mode);
|
eprintf("strtol %s: invalid number\n", h->mode);
|
||||||
if (!(f = fopen(fname, "w")))
|
if (!(f = fopen(fname, "w")))
|
||||||
eprintf("fopen %s:", fname);
|
eprintf("fopen %s:", fname);
|
||||||
if (chmod(fname, mode) < 0)
|
if (chmod(fname, mode) < 0)
|
||||||
|
@ -233,26 +233,26 @@ unarchive(char *fname, ssize_t l, char b[BLKSIZ])
|
||||||
fname, lname);
|
fname, lname);
|
||||||
break;
|
break;
|
||||||
case DIRECTORY:
|
case DIRECTORY:
|
||||||
if ((mode = strtoul(h->mode, &p, 8)) < 0 || *p != '\0')
|
if ((mode = strtol(h->mode, &p, 8)) < 0 || *p != '\0')
|
||||||
eprintf("strtoul %s: invalid number\n", h->mode);
|
eprintf("strtol %s: invalid number\n", h->mode);
|
||||||
if (mkdir(fname, (mode_t)mode) < 0 && errno != EEXIST)
|
if (mkdir(fname, (mode_t)mode) < 0 && errno != EEXIST)
|
||||||
eprintf("mkdir %s:", fname);
|
eprintf("mkdir %s:", fname);
|
||||||
break;
|
break;
|
||||||
case CHARDEV:
|
case CHARDEV:
|
||||||
case BLOCKDEV:
|
case BLOCKDEV:
|
||||||
if ((mode = strtoul(h->mode, &p, 8)) < 0 || *p != '\0')
|
if ((mode = strtol(h->mode, &p, 8)) < 0 || *p != '\0')
|
||||||
eprintf("strtoul %s: invalid number\n", h->mode);
|
eprintf("strtol %s: invalid number\n", h->mode);
|
||||||
if ((major = strtoul(h->major, &p, 8)) < 0 || *p != '\0')
|
if ((major = strtol(h->major, &p, 8)) < 0 || *p != '\0')
|
||||||
eprintf("strtoul %s: invalid number\n", h->major);
|
eprintf("strtol %s: invalid number\n", h->major);
|
||||||
if ((minor = strtoul(h->minor, &p, 8)) < 0 || *p != '\0')
|
if ((minor = strtol(h->minor, &p, 8)) < 0 || *p != '\0')
|
||||||
eprintf("strtoul %s: invalid number\n", h->minor);
|
eprintf("strtol %s: invalid number\n", h->minor);
|
||||||
type = (h->type == CHARDEV) ? S_IFCHR : S_IFBLK;
|
type = (h->type == CHARDEV) ? S_IFCHR : S_IFBLK;
|
||||||
if (mknod(fname, type | mode, makedev(major, minor)) < 0)
|
if (mknod(fname, type | mode, makedev(major, minor)) < 0)
|
||||||
eprintf("mknod %s:", fname);
|
eprintf("mknod %s:", fname);
|
||||||
break;
|
break;
|
||||||
case FIFO:
|
case FIFO:
|
||||||
if ((mode = strtoul(h->mode, &p, 8)) < 0 || *p != '\0')
|
if ((mode = strtol(h->mode, &p, 8)) < 0 || *p != '\0')
|
||||||
eprintf("strtoul %s: invalid number\n", h->mode);
|
eprintf("strtol %s: invalid number\n", h->mode);
|
||||||
if (mknod(fname, S_IFIFO | mode, 0) < 0)
|
if (mknod(fname, S_IFIFO | mode, 0) < 0)
|
||||||
eprintf("mknod %s:", fname);
|
eprintf("mknod %s:", fname);
|
||||||
break;
|
break;
|
||||||
|
@ -260,10 +260,10 @@ unarchive(char *fname, ssize_t l, char b[BLKSIZ])
|
||||||
eprintf("unsupported tar-filetype %c\n", h->type);
|
eprintf("unsupported tar-filetype %c\n", h->type);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((uid = strtoul(h->uid, &p, 8)) < 0 || *p != '\0')
|
if ((uid = strtol(h->uid, &p, 8)) < 0 || *p != '\0')
|
||||||
eprintf("strtoul %s: invalid number\n", h->uid);
|
eprintf("strtol %s: invalid number\n", h->uid);
|
||||||
if ((gid = strtoul(h->gid, &p, 8)) < 0 || *p != '\0')
|
if ((gid = strtol(h->gid, &p, 8)) < 0 || *p != '\0')
|
||||||
eprintf("strtoul %s: invalid number\n", h->gid);
|
eprintf("strtol %s: invalid number\n", h->gid);
|
||||||
if (!getuid() && chown(fname, uid, gid))
|
if (!getuid() && chown(fname, uid, gid))
|
||||||
eprintf("chown %s:", fname);
|
eprintf("chown %s:", fname);
|
||||||
|
|
||||||
|
@ -351,8 +351,8 @@ xt(int (*fn)(char *, ssize_t, char[BLKSIZ]))
|
||||||
estrlcat(fname, "/", sizeof(fname));
|
estrlcat(fname, "/", sizeof(fname));
|
||||||
}
|
}
|
||||||
estrlcat(fname, h->name, sizeof(fname));
|
estrlcat(fname, h->name, sizeof(fname));
|
||||||
if ((size = strtoul(h->size, &p, 8)) < 0 || *p != '\0')
|
if ((size = strtol(h->size, &p, 8)) < 0 || *p != '\0')
|
||||||
eprintf("strtoul %s: invalid number\n", h->size);
|
eprintf("strtol %s: invalid number\n", h->size);
|
||||||
|
|
||||||
fn(fname, size, b);
|
fn(fname, size, b);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user