diff options
author | Philip Guenther <guenther@cvs.openbsd.org> | 2013-07-03 04:08:30 +0000 |
---|---|---|
committer | Philip Guenther <guenther@cvs.openbsd.org> | 2013-07-03 04:08:30 +0000 |
commit | f47e41a433152c4c6b002c5390705ea4cd63800d (patch) | |
tree | 6f0d746eb6484c90b664ce832e6af0589a7ba88f /bin | |
parent | edf0eef297ba31074044e1ec0411618d54ff55da (diff) |
cpio and ustar formats store times in octal fields that are 11 characters
wide, so they support up to 33bits. Take advantage of the extra bits by
no longer forcing them into 32bit ints before the time_t conversion. This
gets us another 204 years of range once time_t changes type
ok deraadt@ tedu@
Diffstat (limited to 'bin')
-rw-r--r-- | bin/pax/cpio.c | 13 | ||||
-rw-r--r-- | bin/pax/extern.h | 4 | ||||
-rw-r--r-- | bin/pax/gen_subs.c | 4 | ||||
-rw-r--r-- | bin/pax/tar.c | 24 |
4 files changed, 26 insertions, 19 deletions
diff --git a/bin/pax/cpio.c b/bin/pax/cpio.c index c9b07b14d6c..33358ec1a52 100644 --- a/bin/pax/cpio.c +++ b/bin/pax/cpio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cpio.c,v 1.21 2013/05/25 13:33:47 lum Exp $ */ +/* $OpenBSD: cpio.c,v 1.22 2013/07/03 04:08:29 guenther Exp $ */ /* $NetBSD: cpio.c,v 1.5 1995/03/21 09:07:13 cgd Exp $ */ /*- @@ -37,6 +37,7 @@ #include <sys/types.h> #include <sys/time.h> #include <sys/stat.h> +#include <limits.h> #include <string.h> #include <stdio.h> #include <unistd.h> @@ -274,6 +275,7 @@ int cpio_rd(ARCHD *arcn, char *buf) { int nsz; + u_quad_t val; HD_CPIO *hd; /* @@ -296,8 +298,11 @@ 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); - arcn->sb.st_mtime = (time_t)asc_ul(hd->c_mtime, sizeof(hd->c_mtime), - OCT); + val = asc_uqd(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_ctime = arcn->sb.st_atime = arcn->sb.st_mtime; # ifdef LONG_OFF_T arcn->sb.st_size = (off_t)asc_ul(hd->c_filesize,sizeof(hd->c_filesize), @@ -448,7 +453,7 @@ cpio_wr(ARCHD *arcn) OCT) || ul_asc((u_long)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), + uqd_asc((u_quad_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)) goto out; diff --git a/bin/pax/extern.h b/bin/pax/extern.h index 1761bccbd46..64697d88d18 100644 --- a/bin/pax/extern.h +++ b/bin/pax/extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: extern.h,v 1.35 2012/12/04 02:27:00 deraadt Exp $ */ +/* $OpenBSD: extern.h,v 1.36 2013/07/03 04:08:29 guenther Exp $ */ /* $NetBSD: extern.h,v 1.5 1996/03/26 23:54:16 mrg Exp $ */ /*- @@ -172,10 +172,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); -#ifndef LONG_OFF_T u_quad_t asc_uqd(char *, int, int); int uqd_asc(u_quad_t, char *, int, int); -#endif size_t fieldcpy(char *, size_t, const char *, size_t); /* diff --git a/bin/pax/gen_subs.c b/bin/pax/gen_subs.c index 551f0307c7b..57390994d8f 100644 --- a/bin/pax/gen_subs.c +++ b/bin/pax/gen_subs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: gen_subs.c,v 1.21 2012/12/04 02:24:45 deraadt Exp $ */ +/* $OpenBSD: gen_subs.c,v 1.22 2013/07/03 04:08:29 guenther Exp $ */ /* $NetBSD: gen_subs.c,v 1.5 1995/03/21 09:07:26 cgd Exp $ */ /*- @@ -302,7 +302,6 @@ ul_asc(u_long val, char *str, int len, int base) return(0); } -#ifndef LONG_OFF_T /* * asc_uqd() * convert hex/octal character string into a u_quad_t. We do not have to @@ -398,7 +397,6 @@ uqd_asc(u_quad_t val, char *str, int len, int base) return(-1); return(0); } -#endif /* * Copy at max min(bufz, fieldsz) chars from field to buf, stopping diff --git a/bin/pax/tar.c b/bin/pax/tar.c index 0823825bf4b..9064a5191d9 100644 --- a/bin/pax/tar.c +++ b/bin/pax/tar.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tar.c,v 1.47 2013/04/11 00:44:26 guenther Exp $ */ +/* $OpenBSD: tar.c,v 1.48 2013/07/03 04:08:29 guenther Exp $ */ /* $NetBSD: tar.c,v 1.5 1995/03/21 09:07:49 cgd Exp $ */ /*- @@ -56,9 +56,7 @@ static size_t expandname(char *, size_t, char **, const 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); -#ifndef LONG_OFF_T static int uqd_oct(u_quad_t, char *, int, int); -#endif #ifndef SMALL static int rd_xheader(ARCHD *, char *, off_t, char); #endif @@ -199,7 +197,6 @@ ul_oct(u_long val, char *str, int len, int term) return(0); } -#ifndef LONG_OFF_T /* * uqd_oct() * convert an u_quad_t to an octal string. one of many oddball field @@ -253,7 +250,6 @@ uqd_oct(u_quad_t val, char *str, int len, int term) return(-1); return(0); } -#endif /* * tar_chksm() @@ -382,6 +378,7 @@ int tar_rd(ARCHD *arcn, char *buf) { HD_TAR *hd; + u_quad_t val; char *pt; /* @@ -412,7 +409,11 @@ tar_rd(ARCHD *arcn, char *buf) #else arcn->sb.st_size = (off_t)asc_uqd(hd->size, sizeof(hd->size), OCT); #endif - arcn->sb.st_mtime = (time_t)asc_ul(hd->mtime, sizeof(hd->mtime), OCT); + val = asc_uqd(hd->mtime, sizeof(hd->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_ctime = arcn->sb.st_atime = arcn->sb.st_mtime; /* @@ -637,7 +638,7 @@ tar_wr(ARCHD *arcn) if (ul_oct((u_long)arcn->sb.st_mode, hd->mode, sizeof(hd->mode), 0) || 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) || - ul_oct((u_long)(u_int)arcn->sb.st_mtime, hd->mtime, sizeof(hd->mtime), 1)) + uqd_oct(arcn->sb.st_mtime, hd->mtime, sizeof(hd->mtime), 1)) goto out; /* @@ -746,6 +747,7 @@ ustar_rd(ARCHD *arcn, char *buf) int cnt = 0; dev_t devmajor; dev_t devminor; + u_quad_t val; /* * we only get proper sized buffers @@ -808,7 +810,11 @@ ustar_rd(ARCHD *arcn, char *buf) #else arcn->sb.st_size = (off_t)asc_uqd(hd->size, sizeof(hd->size), OCT); #endif - arcn->sb.st_mtime = (time_t)asc_ul(hd->mtime, sizeof(hd->mtime), OCT); + val = asc_uqd(hd->mtime, sizeof(hd->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_ctime = arcn->sb.st_atime = arcn->sb.st_mtime; /* @@ -1088,7 +1094,7 @@ ustar_wr(ARCHD *arcn) goto out; } if (ul_oct((u_long)arcn->sb.st_mode, hd->mode, sizeof(hd->mode), 3) || - ul_oct((u_long)(u_int)arcn->sb.st_mtime,hd->mtime,sizeof(hd->mtime),3)) + uqd_oct(arcn->sb.st_mtime, hd->mtime, sizeof(hd->mtime), 3)) goto out; if (!Nflag) { strncpy(hd->uname, name_uid(arcn->sb.st_uid, 0), sizeof(hd->uname)); |