diff options
-rw-r--r-- | bin/pax/cpio.c | 31 | ||||
-rw-r--r-- | bin/pax/tar.c | 12 |
2 files changed, 25 insertions, 18 deletions
diff --git a/bin/pax/cpio.c b/bin/pax/cpio.c index ed20191d6fe..7ff9d642fea 100644 --- a/bin/pax/cpio.c +++ b/bin/pax/cpio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cpio.c,v 1.24 2014/01/08 05:52:47 guenther Exp $ */ +/* $OpenBSD: cpio.c,v 1.25 2014/02/19 03:59:47 guenther Exp $ */ /* $NetBSD: cpio.c,v 1.5 1995/03/21 09:07:13 cgd Exp $ */ /*- @@ -438,8 +438,8 @@ cpio_wr(ARCHD *arcn) OCT) || ul_asc((u_long)arcn->sb.st_rdev, hd->c_rdev, sizeof(hd->c_rdev), OCT) || - uqd_asc((u_quad_t)arcn->sb.st_mtime,hd->c_mtime,sizeof(hd->c_mtime), - OCT) || + uqd_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; @@ -749,8 +749,8 @@ vcpio_wr(ARCHD *arcn) HEX) || ul_asc((u_long)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), - HEX) || + ul_asc(arcn->sb.st_mtime < 0 ? 0 : 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), HEX) || ul_asc((u_long)MAJOR(arcn->sb.st_dev),hd->c_maj, sizeof(hd->c_maj), @@ -1063,14 +1063,19 @@ bcpio_wr(ARCHD *arcn) hd->h_rdev[1] = CHR_WR_3(arcn->sb.st_rdev); if (arcn->sb.st_rdev != (dev_t)(SHRT_EXT(hd->h_rdev))) goto out; - hd->h_mtime_1[0] = CHR_WR_0(arcn->sb.st_mtime); - hd->h_mtime_1[1] = CHR_WR_1(arcn->sb.st_mtime); - hd->h_mtime_2[0] = CHR_WR_2(arcn->sb.st_mtime); - hd->h_mtime_2[1] = CHR_WR_3(arcn->sb.st_mtime); - t_timet = (time_t)(SHRT_EXT(hd->h_mtime_1)); - t_timet = (t_timet << 16) | ((time_t)(SHRT_EXT(hd->h_mtime_2))); - if (arcn->sb.st_mtime != t_timet) - goto out; + if (arcn->sb.st_mtime > 0) { + hd->h_mtime_1[0] = CHR_WR_0(arcn->sb.st_mtime); + hd->h_mtime_1[1] = CHR_WR_1(arcn->sb.st_mtime); + hd->h_mtime_2[0] = CHR_WR_2(arcn->sb.st_mtime); + hd->h_mtime_2[1] = CHR_WR_3(arcn->sb.st_mtime); + t_timet = (time_t)SHRT_EXT(hd->h_mtime_1); + t_timet = t_timet << 16 | (time_t)SHRT_EXT(hd->h_mtime_2); + if (arcn->sb.st_mtime != t_timet) + goto out; + } else { + hd->h_mtime_1[0] = hd->h_mtime_1[1] = 0; + hd->h_mtime_2[0] = hd->h_mtime_2[1] = 0; + } nsz = arcn->nlen + 1; hd->h_namesize[0] = CHR_WR_2(nsz); hd->h_namesize[1] = CHR_WR_3(nsz); diff --git a/bin/pax/tar.c b/bin/pax/tar.c index 1a46545ba7d..5ef507e28fb 100644 --- a/bin/pax/tar.c +++ b/bin/pax/tar.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tar.c,v 1.52 2014/01/08 06:41:49 guenther Exp $ */ +/* $OpenBSD: tar.c,v 1.53 2014/02/19 03:59:47 guenther Exp $ */ /* $NetBSD: tar.c,v 1.5 1995/03/21 09:07:49 cgd Exp $ */ /*- @@ -627,9 +627,10 @@ 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, + 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) || - uqd_oct(arcn->sb.st_mtime, hd->mtime, sizeof(hd->mtime), 1)) + ul_oct((u_long)arcn->sb.st_gid, hd->gid, sizeof(hd->gid), 0)) goto out; /* @@ -1075,8 +1076,9 @@ ustar_wr(ARCHD *arcn) if (ul_oct((u_long)gid_nobody, hd->gid, sizeof(hd->gid), 3)) goto out; } - if (ul_oct((u_long)arcn->sb.st_mode, hd->mode, sizeof(hd->mode), 3) || - uqd_oct(arcn->sb.st_mtime, hd->mtime, sizeof(hd->mtime), 3)) + if (uqd_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; if (!Nflag) { strncpy(hd->uname, name_uid(arcn->sb.st_uid, 0), sizeof(hd->uname)); |