Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/bin/pax PR/46786: Simon Burge: After conversion to 64 bit ti...
details: https://anonhg.NetBSD.org/src/rev/779fc8d6b920
branches: trunk
changeset: 780846:779fc8d6b920
user: christos <christos%NetBSD.org@localhost>
date: Thu Aug 09 08:09:21 2012 +0000
description:
PR/46786: Simon Burge: After conversion to 64 bit time_t, tar/pax/cpio
erroneously think that negative time_t's never fit in 32 bits. Rework
conversion code to always use uintmax_t, and detect negative values.
XXX[1]: Perhaps we should do the same (use a signed conversion) for all
fields not just for time_t
XXX[2]: pullup for 6
diffstat:
bin/pax/cpio.c | 104 +++++++++++++++++++++++-----------------------
bin/pax/extern.h | 12 ++---
bin/pax/gen_subs.c | 63 +++++++++++++++-------------
bin/pax/pax.h | 35 ++++++---------
bin/pax/tar.c | 115 +++++++++++++++++++++++++++-------------------------
5 files changed, 164 insertions(+), 165 deletions(-)
diffs (truncated from 823 to 300 lines):
diff -r bc7a056343b4 -r 779fc8d6b920 bin/pax/cpio.c
--- a/bin/pax/cpio.c Thu Aug 09 07:48:39 2012 +0000
+++ b/bin/pax/cpio.c Thu Aug 09 08:09:21 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cpio.c,v 1.21 2011/03/26 12:01:06 martin Exp $ */
+/* $NetBSD: cpio.c,v 1.22 2012/08/09 08:09:21 christos Exp $ */
/*-
* Copyright (c) 1992 Keith Muller.
@@ -42,7 +42,7 @@
#if 0
static char sccsid[] = "@(#)cpio.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: cpio.c,v 1.21 2011/03/26 12:01:06 martin Exp $");
+__RCSID("$NetBSD: cpio.c,v 1.22 2012/08/09 08:09:21 christos Exp $");
#endif
#endif /* not lint */
@@ -297,15 +297,15 @@
* ascii fields from the header
*/
arcn->pad = 0L;
- arcn->sb.st_dev = (dev_t)asc_ul(hd->c_dev, sizeof(hd->c_dev), OCT);
- arcn->sb.st_ino = (ino_t)asc_ul(hd->c_ino, sizeof(hd->c_ino), OCT);
- arcn->sb.st_mode = (mode_t)asc_ul(hd->c_mode, sizeof(hd->c_mode), OCT);
- arcn->sb.st_uid = (uid_t)asc_ul(hd->c_uid, sizeof(hd->c_uid), OCT);
- arcn->sb.st_gid = (gid_t)asc_ul(hd->c_gid, sizeof(hd->c_gid), OCT);
- arcn->sb.st_nlink = (nlink_t)asc_ul(hd->c_nlink, sizeof(hd->c_nlink),
+ arcn->sb.st_dev = (dev_t)asc_u32(hd->c_dev, sizeof(hd->c_dev), OCT);
+ arcn->sb.st_ino = (ino_t)asc_u32(hd->c_ino, sizeof(hd->c_ino), OCT);
+ arcn->sb.st_mode = (mode_t)asc_u32(hd->c_mode, sizeof(hd->c_mode), OCT);
+ arcn->sb.st_uid = (uid_t)asc_u32(hd->c_uid, sizeof(hd->c_uid), OCT);
+ arcn->sb.st_gid = (gid_t)asc_u32(hd->c_gid, sizeof(hd->c_gid), OCT);
+ arcn->sb.st_nlink = (nlink_t)asc_u32(hd->c_nlink, sizeof(hd->c_nlink),
OCT);
- arcn->sb.st_rdev = (dev_t)asc_ul(hd->c_rdev, sizeof(hd->c_rdev), OCT);
- arcn->sb.st_mtime = (time_t)asc_ul(hd->c_mtime, sizeof(hd->c_mtime),
+ arcn->sb.st_rdev = (dev_t)asc_u32(hd->c_rdev, sizeof(hd->c_rdev), OCT);
+ arcn->sb.st_mtime = (time_t)(int32_t)asc_u32(hd->c_mtime, sizeof(hd->c_mtime),
OCT);
arcn->sb.st_ctime = arcn->sb.st_atime = arcn->sb.st_mtime;
arcn->sb.st_size = (off_t)ASC_OFFT(hd->c_filesize,
@@ -315,7 +315,7 @@
* check name size and if valid, read in the name of this entry (name
* follows header in the archive)
*/
- if ((nsz = (int)asc_ul(hd->c_namesize,sizeof(hd->c_namesize),OCT)) < 2)
+ if ((nsz = (int)asc_u32(hd->c_namesize,sizeof(hd->c_namesize),OCT)) < 2)
return -1;
arcn->nlen = nsz - 1;
if (rd_nm(arcn, nsz) < 0)
@@ -415,7 +415,7 @@
/*
* set data size to hold link name
*/
- if (ul_asc((u_long)arcn->ln_nlen, hd->c_filesize,
+ if (u32_asc((uintmax_t)arcn->ln_nlen, hd->c_filesize,
sizeof(hd->c_filesize), OCT))
goto out;
break;
@@ -423,7 +423,7 @@
/*
* all other file types have no file data
*/
- if (ul_asc((u_long)0, hd->c_filesize, sizeof(hd->c_filesize),
+ if (u32_asc((uintmax_t)0, hd->c_filesize, sizeof(hd->c_filesize),
OCT))
goto out;
break;
@@ -432,24 +432,24 @@
/*
* copy the values to the header using octal ascii
*/
- if (ul_asc((u_long)MAGIC, hd->c_magic, sizeof(hd->c_magic), OCT) ||
- ul_asc((u_long)arcn->sb.st_dev, hd->c_dev, sizeof(hd->c_dev),
+ if (u32_asc((uintmax_t)MAGIC, hd->c_magic, sizeof(hd->c_magic), OCT) ||
+ u32_asc((uintmax_t)arcn->sb.st_dev, hd->c_dev, sizeof(hd->c_dev),
OCT) ||
- ul_asc((u_long)arcn->sb.st_ino, hd->c_ino, sizeof(hd->c_ino),
+ u32_asc((uintmax_t)arcn->sb.st_ino, hd->c_ino, sizeof(hd->c_ino),
OCT) ||
- ul_asc((u_long)arcn->sb.st_mode, hd->c_mode, sizeof(hd->c_mode),
+ u32_asc((uintmax_t)arcn->sb.st_mode, hd->c_mode, sizeof(hd->c_mode),
OCT) ||
- ul_asc((u_long)arcn->sb.st_uid, hd->c_uid, sizeof(hd->c_uid),
+ u32_asc((uintmax_t)arcn->sb.st_uid, hd->c_uid, sizeof(hd->c_uid),
OCT) ||
- ul_asc((u_long)arcn->sb.st_gid, hd->c_gid, sizeof(hd->c_gid),
+ u32_asc((uintmax_t)arcn->sb.st_gid, hd->c_gid, sizeof(hd->c_gid),
OCT) ||
- ul_asc((u_long)arcn->sb.st_nlink, hd->c_nlink, sizeof(hd->c_nlink),
+ u32_asc((uintmax_t)arcn->sb.st_nlink, hd->c_nlink, sizeof(hd->c_nlink),
OCT) ||
- ul_asc((u_long)arcn->sb.st_rdev, hd->c_rdev, sizeof(hd->c_rdev),
+ u32_asc((uintmax_t)arcn->sb.st_rdev, hd->c_rdev, sizeof(hd->c_rdev),
OCT) ||
- ul_asc((u_long)arcn->sb.st_mtime,hd->c_mtime,sizeof(hd->c_mtime),
+ u32_asc((uintmax_t)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))
+ u32_asc((uintmax_t)nsz, hd->c_namesize, sizeof(hd->c_namesize), OCT))
goto out;
/*
@@ -578,29 +578,29 @@
/*
* extract the hex ascii fields from the header
*/
- arcn->sb.st_ino = (ino_t)asc_ul(hd->c_ino, sizeof(hd->c_ino), HEX);
- arcn->sb.st_mode = (mode_t)asc_ul(hd->c_mode, sizeof(hd->c_mode), HEX);
- arcn->sb.st_uid = (uid_t)asc_ul(hd->c_uid, sizeof(hd->c_uid), HEX);
- arcn->sb.st_gid = (gid_t)asc_ul(hd->c_gid, sizeof(hd->c_gid), HEX);
- arcn->sb.st_mtime = (time_t)asc_ul(hd->c_mtime,sizeof(hd->c_mtime),HEX);
+ arcn->sb.st_ino = (ino_t)asc_u32(hd->c_ino, sizeof(hd->c_ino), HEX);
+ arcn->sb.st_mode = (mode_t)asc_u32(hd->c_mode, sizeof(hd->c_mode), HEX);
+ arcn->sb.st_uid = (uid_t)asc_u32(hd->c_uid, sizeof(hd->c_uid), HEX);
+ arcn->sb.st_gid = (gid_t)asc_u32(hd->c_gid, sizeof(hd->c_gid), HEX);
+ arcn->sb.st_mtime = (time_t)(int32_t)asc_u32(hd->c_mtime,sizeof(hd->c_mtime),HEX);
arcn->sb.st_ctime = arcn->sb.st_atime = arcn->sb.st_mtime;
arcn->sb.st_size = (off_t)ASC_OFFT(hd->c_filesize,
sizeof(hd->c_filesize), HEX);
- arcn->sb.st_nlink = (nlink_t)asc_ul(hd->c_nlink, sizeof(hd->c_nlink),
+ arcn->sb.st_nlink = (nlink_t)asc_u32(hd->c_nlink, sizeof(hd->c_nlink),
HEX);
- devmajor = (dev_t)asc_ul(hd->c_maj, sizeof(hd->c_maj), HEX);
- devminor = (dev_t)asc_ul(hd->c_min, sizeof(hd->c_min), HEX);
+ devmajor = (dev_t)asc_u32(hd->c_maj, sizeof(hd->c_maj), HEX);
+ devminor = (dev_t)asc_u32(hd->c_min, sizeof(hd->c_min), HEX);
arcn->sb.st_dev = TODEV(devmajor, devminor);
- devmajor = (dev_t)asc_ul(hd->c_rmaj, sizeof(hd->c_maj), HEX);
- devminor = (dev_t)asc_ul(hd->c_rmin, sizeof(hd->c_min), HEX);
+ devmajor = (dev_t)asc_u32(hd->c_rmaj, sizeof(hd->c_maj), HEX);
+ devminor = (dev_t)asc_u32(hd->c_rmin, sizeof(hd->c_min), HEX);
arcn->sb.st_rdev = TODEV(devmajor, devminor);
- arcn->crc = asc_ul(hd->c_chksum, sizeof(hd->c_chksum), HEX);
+ arcn->crc = asc_u32(hd->c_chksum, sizeof(hd->c_chksum), HEX);
/*
* check the length of the file name, if ok read it in, return -1 if
* bogus
*/
- if ((nsz = (int)asc_ul(hd->c_namesize,sizeof(hd->c_namesize),HEX)) < 2)
+ if ((nsz = (int)asc_u32(hd->c_namesize,sizeof(hd->c_namesize),HEX)) < 2)
return -1;
arcn->nlen = nsz - 1;
if (rd_nm(arcn, nsz) < 0)
@@ -699,15 +699,15 @@
* file data crc's, and the crc if needed.
*/
if (docrc) {
- if (ul_asc((u_long)VCMAGIC, hd->c_magic, sizeof(hd->c_magic),
+ if (u32_asc((uintmax_t)VCMAGIC, hd->c_magic, sizeof(hd->c_magic),
OCT) ||
- ul_asc((u_long)arcn->crc,hd->c_chksum,sizeof(hd->c_chksum),
+ u32_asc((uintmax_t)arcn->crc,hd->c_chksum,sizeof(hd->c_chksum),
HEX))
goto out;
} else {
- if (ul_asc((u_long)VMAGIC, hd->c_magic, sizeof(hd->c_magic),
+ if (u32_asc((uintmax_t)VMAGIC, hd->c_magic, sizeof(hd->c_magic),
OCT) ||
- ul_asc((u_long)0L, hd->c_chksum, sizeof(hd->c_chksum),HEX))
+ u32_asc((uintmax_t)0, hd->c_chksum, sizeof(hd->c_chksum),HEX))
goto out;
}
@@ -733,7 +733,7 @@
* the size of the link
*/
arcn->pad = 0L;
- if (ul_asc((u_long)arcn->ln_nlen, hd->c_filesize,
+ if (u32_asc((uintmax_t)arcn->ln_nlen, hd->c_filesize,
sizeof(hd->c_filesize), HEX))
goto out;
break;
@@ -742,7 +742,7 @@
* no file data for the caller to process
*/
arcn->pad = 0L;
- if (ul_asc((u_long)0L, hd->c_filesize, sizeof(hd->c_filesize),
+ if (u32_asc((uintmax_t)0, hd->c_filesize, sizeof(hd->c_filesize),
HEX))
goto out;
break;
@@ -751,27 +751,27 @@
/*
* set the other fields in the header
*/
- if (ul_asc((u_long)arcn->sb.st_ino, hd->c_ino, sizeof(hd->c_ino),
+ if (u32_asc((uintmax_t)arcn->sb.st_ino, hd->c_ino, sizeof(hd->c_ino),
HEX) ||
- ul_asc((u_long)arcn->sb.st_mode, hd->c_mode, sizeof(hd->c_mode),
+ u32_asc((uintmax_t)arcn->sb.st_mode, hd->c_mode, sizeof(hd->c_mode),
HEX) ||
- ul_asc((u_long)arcn->sb.st_uid, hd->c_uid, sizeof(hd->c_uid),
+ u32_asc((uintmax_t)arcn->sb.st_uid, hd->c_uid, sizeof(hd->c_uid),
HEX) ||
- ul_asc((u_long)arcn->sb.st_gid, hd->c_gid, sizeof(hd->c_gid),
+ u32_asc((uintmax_t)arcn->sb.st_gid, hd->c_gid, sizeof(hd->c_gid),
HEX) ||
- ul_asc((u_long)arcn->sb.st_mtime, hd->c_mtime, sizeof(hd->c_mtime),
+ u32_asc((uintmax_t)arcn->sb.st_mtime, hd->c_mtime, sizeof(hd->c_mtime),
HEX) ||
- ul_asc((u_long)arcn->sb.st_nlink, hd->c_nlink, sizeof(hd->c_nlink),
+ u32_asc((uintmax_t)arcn->sb.st_nlink, hd->c_nlink, sizeof(hd->c_nlink),
HEX) ||
- ul_asc((u_long)MAJOR(arcn->sb.st_dev),hd->c_maj, sizeof(hd->c_maj),
+ u32_asc((uintmax_t)MAJOR(arcn->sb.st_dev),hd->c_maj, sizeof(hd->c_maj),
HEX) ||
- ul_asc((u_long)MINOR(arcn->sb.st_dev),hd->c_min, sizeof(hd->c_min),
+ u32_asc((uintmax_t)MINOR(arcn->sb.st_dev),hd->c_min, sizeof(hd->c_min),
HEX) ||
- ul_asc((u_long)MAJOR(arcn->sb.st_rdev),hd->c_rmaj,sizeof(hd->c_maj),
+ u32_asc((uintmax_t)MAJOR(arcn->sb.st_rdev),hd->c_rmaj,sizeof(hd->c_maj),
HEX) ||
- ul_asc((u_long)MINOR(arcn->sb.st_rdev),hd->c_rmin,sizeof(hd->c_min),
+ u32_asc((uintmax_t)MINOR(arcn->sb.st_rdev),hd->c_rmin,sizeof(hd->c_min),
HEX) ||
- ul_asc((u_long)nsz, hd->c_namesize, sizeof(hd->c_namesize), HEX))
+ u32_asc((uintmax_t)nsz, hd->c_namesize, sizeof(hd->c_namesize), HEX))
goto out;
/*
diff -r bc7a056343b4 -r 779fc8d6b920 bin/pax/extern.h
--- a/bin/pax/extern.h Thu Aug 09 07:48:39 2012 +0000
+++ b/bin/pax/extern.h Thu Aug 09 08:09:21 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: extern.h,v 1.58 2011/08/29 14:47:47 joerg Exp $ */
+/* $NetBSD: extern.h,v 1.59 2012/08/09 08:09:21 christos Exp $ */
/*-
* Copyright (c) 1992 Keith Muller.
@@ -181,12 +181,10 @@
void ls_list(ARCHD *, time_t, FILE *);
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);
-#if !defined(_LP64)
-unsigned long long asc_ull(char *, int, int);
-int ull_asc(unsigned long long, char *, int, int);
-#endif
+uint32_t asc_u32(char *, int, int);
+int u32_asc(uintmax_t, char *, int, int);
+uintmax_t asc_umax(char *, int, int);
+int umax_asc(uintmax_t, char *, int, int);
int check_Aflag(void);
/*
diff -r bc7a056343b4 -r 779fc8d6b920 bin/pax/gen_subs.c
--- a/bin/pax/gen_subs.c Thu Aug 09 07:48:39 2012 +0000
+++ b/bin/pax/gen_subs.c Thu Aug 09 08:09:21 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: gen_subs.c,v 1.35 2011/08/14 10:49:58 christos Exp $ */
+/* $NetBSD: gen_subs.c,v 1.36 2012/08/09 08:09:21 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.35 2011/08/14 10:49:58 christos Exp $");
+__RCSID("$NetBSD: gen_subs.c,v 1.36 2012/08/09 08:09:21 christos Exp $");
#endif
#endif /* not lint */
@@ -202,20 +202,20 @@
}
/*
- * asc_ul()
- * convert hex/octal character string into a u_long. We do not have to
+ * asc_u32()
+ * convert hex/octal character string into a uint32_t. 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:
- * unsigned long value
+ * uint32_t value
*/
-u_long
-asc_ul(char *str, int len, int base)
+uint32_t
+asc_u32(char *str, int len, int base)
{
char *stop;
- u_long tval = 0;
+ uint32_t tval = 0;
stop = str + len;
@@ -248,17 +248,24 @@
}
/*
- * ul_asc()
- * convert an unsigned long into an hex/oct ascii string. pads with LEADING
Home |
Main Index |
Thread Index |
Old Index