Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/bin/pax Add base-256 decoding support (Micha Gorny)



details:   https://anonhg.NetBSD.org/src/rev/0b154c13c7e2
branches:  trunk
changeset: 837345:0b154c13c7e2
user:      christos <christos%NetBSD.org@localhost>
date:      Fri Nov 30 00:53:11 2018 +0000

description:
Add base-256 decoding support (Micha Gorny)

diffstat:

 bin/pax/gen_subs.c |  34 ++++++++++++++++++++++++++++------
 bin/pax/tar.c      |   8 ++++++--
 2 files changed, 34 insertions(+), 8 deletions(-)

diffs (100 lines):

diff -r 300054c906f0 -r 0b154c13c7e2 bin/pax/gen_subs.c
--- a/bin/pax/gen_subs.c        Thu Nov 29 23:53:44 2018 +0000
+++ b/bin/pax/gen_subs.c        Fri Nov 30 00:53:11 2018 +0000
@@ -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 @@
 
 /*
  * 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
@@ -323,6 +321,30 @@
        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
         */
        while ((str < stop) && ((*str == ' ') || (*str == '0')))
diff -r 300054c906f0 -r 0b154c13c7e2 bin/pax/tar.c
--- a/bin/pax/tar.c     Thu Nov 29 23:53:44 2018 +0000
+++ b/bin/pax/tar.c     Fri Nov 30 00:53:11 2018 +0000
@@ -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 @@
        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 @@
        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;
 



Home | Main Index | Thread Index | Old Index