u_quad_t is a remanent of the distant pre-long long past, so let's stop 
using it in pax.  For consistency, replace "uqd" with "ull" in the names 
of the involved functions.

There are a couple amusing spots in gen_subs.c:
                        if ((val = (val >> 4)) == (u_quad_t)0)
                                break;
...
                        if ((val = (val >> 3)) == (u_quad_t)0)
                                break;

The cast was pointless, but that's kinda confusing as is, so I'm pulling 
the assignment out and making the first of these:
                        val >>= 4;
                        if (val == 0)
                                break;

Tested by archiving, listing, and restoring a file with a date in 2100.

ok?

Philip Guenther


Index: cpio.c
===================================================================
RCS file: /data/src/openbsd/src/bin/pax/cpio.c,v
retrieving revision 1.27
diff -u -p -r1.27 cpio.c
--- cpio.c      19 Mar 2015 05:14:24 -0000      1.27
+++ cpio.c      14 Aug 2016 00:36:41 -0000
@@ -270,7 +270,7 @@ int
 cpio_rd(ARCHD *arcn, char *buf)
 {
        int nsz;
-       u_quad_t val;
+       unsigned long long val;
        HD_CPIO *hd;
 
        /*
@@ -293,14 +293,14 @@ cpio_rd(ARCHD *arcn, char *buf)
        arcn->sb.st_nlink = (nlink_t)asc_ul(hd->c_nlink, sizeof(hd->c_nlink),
            OCT);
        arcn->sb.st_rdev = (dev_t)asc_ul(hd->c_rdev, sizeof(hd->c_rdev), OCT);
-       val = asc_uqd(hd->c_mtime, sizeof(hd->c_mtime), OCT);
+       val = asc_ull(hd->c_mtime, sizeof(hd->c_mtime), OCT);
        if ((time_t)val < 0 || (time_t)val != val)
                arcn->sb.st_mtime = INT_MAX;                    /* XXX 2038 */
        else
                arcn->sb.st_mtime = val;
        arcn->sb.st_mtim.tv_nsec = 0;
        arcn->sb.st_ctim = arcn->sb.st_atim = arcn->sb.st_mtim;
-       arcn->sb.st_size = (off_t)asc_uqd(hd->c_filesize,sizeof(hd->c_filesize),
+       arcn->sb.st_size = (off_t)asc_ull(hd->c_filesize,sizeof(hd->c_filesize),
            OCT);
 
        /*
@@ -396,7 +396,7 @@ cpio_wr(ARCHD *arcn)
                /*
                 * set data size for file data
                 */
-               if (uqd_asc((u_quad_t)arcn->sb.st_size, hd->c_filesize,
+               if (ull_asc(arcn->sb.st_size, hd->c_filesize,
                    sizeof(hd->c_filesize), OCT)) {
                        paxwarn(1,"File is too large for cpio format %s",
                            arcn->org_name);
@@ -439,7 +439,7 @@ cpio_wr(ARCHD *arcn)
                 OCT) ||
            ul_asc((u_long)arcn->sb.st_rdev, hd->c_rdev, sizeof(hd->c_rdev),
                OCT) ||
-           uqd_asc(arcn->sb.st_mtime < 0 ? 0 : arcn->sb.st_mtime, hd->c_mtime,
+           ull_asc(arcn->sb.st_mtime < 0 ? 0 : arcn->sb.st_mtime, hd->c_mtime,
                sizeof(hd->c_mtime), OCT) ||
            ul_asc((u_long)nsz, hd->c_namesize, sizeof(hd->c_namesize), OCT))
                goto out;
@@ -575,7 +575,7 @@ vcpio_rd(ARCHD *arcn, char *buf)
        arcn->sb.st_mtime = (time_t)asc_ul(hd->c_mtime,sizeof(hd->c_mtime),HEX);
        arcn->sb.st_mtim.tv_nsec = 0;
        arcn->sb.st_ctim = arcn->sb.st_atim = arcn->sb.st_mtim;
-       arcn->sb.st_size = (off_t)asc_uqd(hd->c_filesize,
+       arcn->sb.st_size = (off_t)asc_ull(hd->c_filesize,
            sizeof(hd->c_filesize), HEX);
        arcn->sb.st_nlink = (nlink_t)asc_ul(hd->c_nlink, sizeof(hd->c_nlink),
            HEX);
@@ -711,7 +711,7 @@ vcpio_wr(ARCHD *arcn)
                 * much to pad.
                 */
                arcn->pad = VCPIO_PAD(arcn->sb.st_size);
-               if (uqd_asc((u_quad_t)arcn->sb.st_size, hd->c_filesize,
+               if (ull_asc(arcn->sb.st_size, hd->c_filesize,
                    sizeof(hd->c_filesize), HEX)) {
                        paxwarn(1,"File is too large for sv4cpio format %s",
                            arcn->org_name);
Index: extern.h
===================================================================
RCS file: /data/src/openbsd/src/bin/pax/extern.h,v
retrieving revision 1.54
diff -u -p -r1.54 extern.h
--- extern.h    1 Jan 2016 15:56:03 -0000       1.54
+++ extern.h    14 Aug 2016 00:36:00 -0000
@@ -174,8 +174,8 @@ void ls_tty(ARCHD *);
 void safe_print(const char *, FILE *);
 u_long asc_ul(char *, int, int);
 int ul_asc(u_long, char *, int, int);
-u_quad_t asc_uqd(char *, int, int);
-int uqd_asc(u_quad_t, char *, int, int);
+unsigned long long asc_ull(char *, int, int);
+int ull_asc(unsigned long long, char *, int, int);
 size_t fieldcpy(char *, size_t, const char *, size_t);
 
 /*
Index: gen_subs.c
===================================================================
RCS file: /data/src/openbsd/src/bin/pax/gen_subs.c,v
retrieving revision 1.28
diff -u -p -r1.28 gen_subs.c
--- gen_subs.c  17 Mar 2015 03:23:17 -0000      1.28
+++ gen_subs.c  14 Aug 2016 00:36:10 -0000
@@ -251,13 +251,15 @@ ul_asc(u_long val, char *str, int len, i
                                *pt-- = '0' + (char)digit;
                        else
                                *pt-- = 'a' + (char)(digit - 10);
-                       if ((val = (val >> 4)) == (u_long)0)
+                       val >>= 4;
+                       if (val == 0)
                                break;
                }
        } else {
                while (pt >= str) {
                        *pt-- = '0' + (char)(val & 0x7);
-                       if ((val = (val >> 3)) == (u_long)0)
+                       val >>= 3;
+                       if (val == 0)
                                break;
                }
        }
@@ -267,26 +269,26 @@ ul_asc(u_long val, char *str, int len, i
         */
        while (pt >= str)
                *pt-- = '0';
-       if (val != (u_long)0)
+       if (val != 0)
                return(-1);
        return(0);
 }
 
 /*
- * asc_uqd()
- *     convert hex/octal character string into a u_quad_t. We do not have to
- *     check for overflow! (the headers in all supported formats are not large
- *     enough to create an overflow).
+ * asc_ull()
+ *     Convert hex/octal character string into a unsigned long long.
+ *     We do not have to check for overflow!  (The headers in all
+ *     supported formats are not large enough to create an overflow).
  *     NOTE: strings passed to us are NOT TERMINATED.
  * Return:
- *     u_quad_t value
+ *     unsigned long long value
  */
 
-u_quad_t
-asc_uqd(char *str, int len, int base)
+unsigned long long
+asc_ull(char *str, int len, int base)
 {
        char *stop;
-       u_quad_t tval = 0;
+       unsigned long long tval = 0;
 
        stop = str + len;
 
@@ -319,17 +321,17 @@ asc_uqd(char *str, int len, int base)
 }
 
 /*
- * uqd_asc()
- *     convert an u_quad_t into a hex/oct ascii string. pads with LEADING
- *     ascii 0's to fill string completely
+ * ull_asc()
+ *     Convert an unsigned long long into a hex/oct ascii string.
+ *     Pads with LEADING ascii 0's to fill string completely
  *     NOTE: the string created is NOT TERMINATED.
  */
 
 int
-uqd_asc(u_quad_t val, char *str, int len, int base)
+ull_asc(unsigned long long val, char *str, int len, int base)
 {
        char *pt;
-       u_quad_t digit;
+       unsigned long long digit;
 
        /*
         * WARNING str is not '\0' terminated by this routine
@@ -347,13 +349,15 @@ uqd_asc(u_quad_t val, char *str, int len
                                *pt-- = '0' + (char)digit;
                        else
                                *pt-- = 'a' + (char)(digit - 10);
-                       if ((val = (val >> 4)) == (u_quad_t)0)
+                       val >>= 4;
+                       if (val == 0)
                                break;
                }
        } else {
                while (pt >= str) {
                        *pt-- = '0' + (char)(val & 0x7);
-                       if ((val = (val >> 3)) == (u_quad_t)0)
+                       val >>= 3;
+                       if (val == 0)
                                break;
                }
        }
@@ -363,7 +367,7 @@ uqd_asc(u_quad_t val, char *str, int len
         */
        while (pt >= str)
                *pt-- = '0';
-       if (val != (u_quad_t)0)
+       if (val != 0)
                return(-1);
        return(0);
 }
Index: options.c
===================================================================
RCS file: /data/src/openbsd/src/bin/pax/options.c,v
retrieving revision 1.93
diff -u -p -r1.93 options.c
--- options.c   19 Apr 2016 03:26:11 -0000      1.93
+++ options.c   14 Aug 2016 00:12:35 -0000
@@ -1373,7 +1373,7 @@ printflg(unsigned int flg)
 
        (void)fprintf(stderr,"%s: Invalid combination of options:", argv0);
        while ((nxt = ffs(flg)) != 0) {
-               flg = flg >> nxt;
+               flg >>= nxt;
                pos += nxt;
                (void)fprintf(stderr, " -%c", flgch[pos-1]);
        }
Index: tar.c
===================================================================
RCS file: /data/src/openbsd/src/bin/pax/tar.c,v
retrieving revision 1.59
diff -u -p -r1.59 tar.c
--- tar.c       15 Feb 2016 02:38:53 -0000      1.59
+++ tar.c       14 Aug 2016 00:36:28 -0000
@@ -56,7 +56,7 @@ static size_t expandname(char *, size_t,
 static u_long tar_chksm(char *, int);
 static char *name_split(char *, int);
 static int ul_oct(u_long, char *, int, int);
-static int uqd_oct(u_quad_t, char *, int, int);
+static int ull_oct(unsigned long long, char *, int, int);
 #ifndef SMALL
 static int rd_xheader(ARCHD *arcn, int, off_t);
 #endif
@@ -186,30 +186,31 @@ ul_oct(u_long val, char *str, int len, i
         */
        while (pt >= str) {
                *pt-- = '0' + (char)(val & 0x7);
-               if ((val = val >> 3) == (u_long)0)
+               val >>= 3;
+               if (val == 0)
                        break;
        }
 
        while (pt >= str)
                *pt-- = '0';
-       if (val != (u_long)0)
+       if (val != 0)
                return(-1);
        return(0);
 }
 
 /*
- * uqd_oct()
- *     convert an u_quad_t to an octal string. one of many oddball field
- *     termination characters are used by the various versions of tar in the
- *     different fields. term selects which kind to use. str is '0' padded
- *     at the front to len. we are unable to use only one format as many old
- *     tar readers are very cranky about this.
+ * ull_oct()
+ *     Convert an unsigned long long to an octal string.  One of many oddball
+ *     field termination characters are used by the various versions of tar
+ *     in the different fields.  term selects which kind to use.  str is
+ *     '0' padded at the front to len.  We are unable to use only one format
+ *     as many old tar readers are very cranky about this.
  * Return:
  *     0 if the number fit into the string, -1 otherwise
  */
 
 static int
-uqd_oct(u_quad_t val, char *str, int len, int term)
+ull_oct(unsigned long long val, char *str, int len, int term)
 {
        char *pt;
 
@@ -240,13 +241,14 @@ uqd_oct(u_quad_t val, char *str, int len
         */
        while (pt >= str) {
                *pt-- = '0' + (char)(val & 0x7);
-               if ((val = val >> 3) == 0)
+               val >>= 3;
+               if (val == 0)
                        break;
        }
 
        while (pt >= str)
                *pt-- = '0';
-       if (val != (u_quad_t)0)
+       if (val != 0)
                return(-1);
        return(0);
 }
@@ -378,7 +380,7 @@ int
 tar_rd(ARCHD *arcn, char *buf)
 {
        HD_TAR *hd;
-       u_quad_t val;
+       unsigned long long val;
        char *pt;
 
        /*
@@ -404,8 +406,8 @@ tar_rd(ARCHD *arcn, char *buf)
            0xfff);
        arcn->sb.st_uid = (uid_t)asc_ul(hd->uid, sizeof(hd->uid), OCT);
        arcn->sb.st_gid = (gid_t)asc_ul(hd->gid, sizeof(hd->gid), OCT);
-       arcn->sb.st_size = (off_t)asc_uqd(hd->size, sizeof(hd->size), OCT);
-       val = asc_uqd(hd->mtime, sizeof(hd->mtime), OCT);
+       arcn->sb.st_size = (off_t)asc_ull(hd->size, sizeof(hd->size), OCT);
+       val = asc_ull(hd->mtime, sizeof(hd->mtime), OCT);
        if ((time_t)val < 0 || (time_t)val != val)
                arcn->sb.st_mtime = INT_MAX;                    /* XXX 2038 */
        else
@@ -615,9 +617,9 @@ tar_wr(ARCHD *arcn)
                 * data follows this file, so set the pad
                 */
                hd->linkflag = AREGTYPE;
-               if (uqd_oct((u_quad_t)arcn->sb.st_size, hd->size,
-                   sizeof(hd->size), 1)) {
-                       paxwarn(1,"File is too large for tar %s", 
arcn->org_name);
+               if (ull_oct(arcn->sb.st_size, hd->size, sizeof(hd->size), 1)) {
+                       paxwarn(1, "File is too large for tar %s",
+                           arcn->org_name);
                        return(1);
                }
                arcn->pad = TAR_PAD(arcn->sb.st_size);
@@ -627,7 +629,7 @@ tar_wr(ARCHD *arcn)
         * copy those fields that are independent of the type
         */
        if (ul_oct((u_long)arcn->sb.st_mode, hd->mode, sizeof(hd->mode), 0) ||
-           uqd_oct(arcn->sb.st_mtime < 0 ? 0 : arcn->sb.st_mtime, hd->mtime,
+           ull_oct(arcn->sb.st_mtime < 0 ? 0 : arcn->sb.st_mtime, hd->mtime,
                sizeof(hd->mtime), 1) ||
            ul_oct((u_long)arcn->sb.st_uid, hd->uid, sizeof(hd->uid), 0) ||
            ul_oct((u_long)arcn->sb.st_gid, hd->gid, sizeof(hd->gid), 0))
@@ -739,7 +741,7 @@ ustar_rd(ARCHD *arcn, char *buf)
        int cnt = 0;
        dev_t devmajor;
        dev_t devminor;
-       u_quad_t val;
+       unsigned long long val;
 
        /*
         * we only get proper sized buffers
@@ -809,8 +811,8 @@ reset:
         */
        arcn->sb.st_mode = (mode_t)(asc_ul(hd->mode, sizeof(hd->mode), OCT) &
            0xfff);
-       arcn->sb.st_size = (off_t)asc_uqd(hd->size, sizeof(hd->size), OCT);
-       val = asc_uqd(hd->mtime, sizeof(hd->mtime), OCT);
+       arcn->sb.st_size = (off_t)asc_ull(hd->size, sizeof(hd->size), OCT);
+       val = asc_ull(hd->mtime, sizeof(hd->mtime), OCT);
        if ((time_t)val < 0 || (time_t)val != val)
                arcn->sb.st_mtime = INT_MAX;                    /* XXX 2038 */
        else
@@ -1044,9 +1046,9 @@ ustar_wr(ARCHD *arcn)
                else
                        hd->typeflag = REGTYPE;
                arcn->pad = TAR_PAD(arcn->sb.st_size);
-               if (uqd_oct((u_quad_t)arcn->sb.st_size, hd->size,
-                   sizeof(hd->size), 3)) {
-                       paxwarn(1,"File is too long for ustar 
%s",arcn->org_name);
+               if (ull_oct(arcn->sb.st_size, hd->size, sizeof(hd->size), 3)) {
+                       paxwarn(1, "File is too long for ustar %s",
+                           arcn->org_name);
                        return(1);
                }
                break;
@@ -1087,7 +1089,7 @@ ustar_wr(ARCHD *arcn)
                if (ul_oct((u_long)gid_nobody, hd->gid, sizeof(hd->gid), 3))
                        goto out;
        }
-       if (uqd_oct(arcn->sb.st_mtime < 0 ? 0 : arcn->sb.st_mtime, hd->mtime,
+       if (ull_oct(arcn->sb.st_mtime < 0 ? 0 : arcn->sb.st_mtime, hd->mtime,
                sizeof(hd->mtime), 3) ||
            ul_oct((u_long)arcn->sb.st_mode, hd->mode, sizeof(hd->mode), 3))
                goto out;

Reply via email to