Add base-256 decoding support (Micha Gorny)
This commit is contained in:
parent
0cc465725e
commit
a4c163faee
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: gen_subs.c,v 1.36 2012/08/09 08:09:21 christos Exp $ */
|
||||
/* $NetBSD: gen_subs.c,v 1.37 2018/11/30 00:53:11 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992 Keith Muller.
|
||||
@ -42,7 +42,7 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)gen_subs.c 8.1 (Berkeley) 5/31/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: gen_subs.c,v 1.36 2012/08/09 08:09:21 christos Exp $");
|
||||
__RCSID("$NetBSD: gen_subs.c,v 1.37 2018/11/30 00:53:11 christos Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -306,12 +306,10 @@ u32_asc(uintmax_t val, char *str, int len, int base)
|
||||
|
||||
/*
|
||||
* asc_umax()
|
||||
* convert hex/octal character string into a uintmax. We do
|
||||
* not have to to check for overflow! (the headers in all supported
|
||||
* formats are not large enough to create an overflow).
|
||||
* convert hex/octal/base-256 value into a uintmax.
|
||||
* NOTE: strings passed to us are NOT TERMINATED.
|
||||
* Return:
|
||||
* uintmax_t value
|
||||
* uintmax_t value; UINTMAX_MAX for overflow/negative
|
||||
*/
|
||||
|
||||
uintmax_t
|
||||
@ -322,6 +320,30 @@ asc_umax(char *str, int len, int base)
|
||||
|
||||
stop = str + len;
|
||||
|
||||
/*
|
||||
* if the highest bit of first byte is set, it's base-256 encoded
|
||||
* (base-256 is basically (n-1)-bit big endian signed
|
||||
*/
|
||||
if (str < stop && (*str & 0x80)) {
|
||||
/*
|
||||
* uintmax_t can't be negative, so fail on negative numbers
|
||||
*/
|
||||
if (*str & 0x40)
|
||||
return UINTMAX_MAX;
|
||||
|
||||
tval = *str++ & 0x3f;
|
||||
while (str < stop) {
|
||||
/*
|
||||
* check for overflow
|
||||
*/
|
||||
if (tval > (UINTMAX_MAX/256))
|
||||
return UINTMAX_MAX;
|
||||
tval = (tval << 8) | ((*str++) & 0xFF);
|
||||
}
|
||||
|
||||
return tval;
|
||||
}
|
||||
|
||||
/*
|
||||
* skip over leading blanks and zeros
|
||||
*/
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: tar.c,v 1.73 2015/12/19 18:28:54 christos Exp $ */
|
||||
/* $NetBSD: tar.c,v 1.74 2018/11/30 00:53:11 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992 Keith Muller.
|
||||
@ -42,7 +42,7 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)tar.c 8.2 (Berkeley) 4/18/94";
|
||||
#else
|
||||
__RCSID("$NetBSD: tar.c,v 1.73 2015/12/19 18:28:54 christos Exp $");
|
||||
__RCSID("$NetBSD: tar.c,v 1.74 2018/11/30 00:53:11 christos Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -486,6 +486,8 @@ tar_rd(ARCHD *arcn, char *buf)
|
||||
arcn->sb.st_uid = (uid_t)asc_u32(hd->uid, sizeof(hd->uid), OCT);
|
||||
arcn->sb.st_gid = (gid_t)asc_u32(hd->gid, sizeof(hd->gid), OCT);
|
||||
arcn->sb.st_size = (off_t)ASC_OFFT(hd->size, sizeof(hd->size), OCT);
|
||||
if (arcn->sb.st_size == -1)
|
||||
return -1;
|
||||
arcn->sb.st_mtime = (time_t)(int32_t)asc_u32(hd->mtime, sizeof(hd->mtime), OCT);
|
||||
arcn->sb.st_ctime = arcn->sb.st_atime = arcn->sb.st_mtime;
|
||||
|
||||
@ -860,6 +862,8 @@ ustar_rd(ARCHD *arcn, char *buf)
|
||||
arcn->sb.st_mode = (mode_t)(asc_u32(hd->mode, sizeof(hd->mode), OCT) &
|
||||
0xfff);
|
||||
arcn->sb.st_size = (off_t)ASC_OFFT(hd->size, sizeof(hd->size), OCT);
|
||||
if (arcn->sb.st_size == -1)
|
||||
return -1;
|
||||
arcn->sb.st_mtime = (time_t)(int32_t)asc_u32(hd->mtime, sizeof(hd->mtime), OCT);
|
||||
arcn->sb.st_ctime = arcn->sb.st_atime = arcn->sb.st_mtime;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user