diff options
author | Mike Belopuhov <mikeb@cvs.openbsd.org> | 2016-02-04 12:45:04 +0000 |
---|---|---|
committer | Mike Belopuhov <mikeb@cvs.openbsd.org> | 2016-02-04 12:45:04 +0000 |
commit | 2c2937f9fea3761c79fb88f130dfe5af42a61b5d (patch) | |
tree | bf090ef4ba7d227c3abec6e845514a47dc4e86bb | |
parent | e0827dc97dee2c985bab40810663c9338a8388b5 (diff) |
Prevent signed overflow when calculating i_modrev initial value
Reported and fixed by Martin Natano <natano at natano ! net>, thanks!
ok stefan
-rw-r--r-- | sys/ufs/ext2fs/ext2fs_subr.c | 25 | ||||
-rw-r--r-- | sys/ufs/ufs/ufs_vnops.c | 24 |
2 files changed, 6 insertions, 43 deletions
diff --git a/sys/ufs/ext2fs/ext2fs_subr.c b/sys/ufs/ext2fs/ext2fs_subr.c index de1a11fab53..6e036c5a130 100644 --- a/sys/ufs/ext2fs/ext2fs_subr.c +++ b/sys/ufs/ext2fs/ext2fs_subr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ext2fs_subr.c,v 1.33 2015/03/14 03:38:52 jsg Exp $ */ +/* $OpenBSD: ext2fs_subr.c,v 1.34 2016/02/04 12:45:03 mikeb Exp $ */ /* $NetBSD: ext2fs_subr.c,v 1.1 1997/06/11 09:34:03 bouyer Exp $ */ /* @@ -49,25 +49,6 @@ #include <ufs/ext2fs/ext2fs_extern.h> #include <ufs/ext2fs/ext2fs_extents.h> -union _qcvt { - int64_t qcvt; - int32_t val[2]; -}; - -#define SETHIGH(q, h) { \ - union _qcvt tmp; \ - tmp.qcvt = (q); \ - tmp.val[_QUAD_HIGHWORD] = (h); \ - (q) = tmp.qcvt; \ -} - -#define SETLOW(q, l) { \ - union _qcvt tmp; \ - tmp.qcvt = (q); \ - tmp.val[_QUAD_LOWWORD] = (l); \ - (q) = tmp.qcvt; \ -} - #ifdef _KERNEL /* @@ -220,8 +201,8 @@ ext2fs_vinit(struct mount *mp, struct vops *specops, /* Initialize modrev times */ getmicrouptime(&tv); - SETHIGH(ip->i_modrev, tv.tv_sec); - SETLOW(ip->i_modrev, tv.tv_usec * 4294); + ip->i_modrev = (u_quad_t)tv.tv_sec << 32; + ip->i_modrev |= (u_quad_t)tv.tv_usec * 4294; *vpp = vp; diff --git a/sys/ufs/ufs/ufs_vnops.c b/sys/ufs/ufs/ufs_vnops.c index 700ccc1b2a2..4d15c8bc946 100644 --- a/sys/ufs/ufs/ufs_vnops.c +++ b/sys/ufs/ufs/ufs_vnops.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ufs_vnops.c,v 1.123 2015/12/08 15:31:01 tedu Exp $ */ +/* $OpenBSD: ufs_vnops.c,v 1.124 2016/02/04 12:45:03 mikeb Exp $ */ /* $NetBSD: ufs_vnops.c,v 1.18 1996/05/11 18:28:04 mycroft Exp $ */ /* @@ -78,24 +78,6 @@ int filt_ufswrite(struct knote *, long); int filt_ufsvnode(struct knote *, long); void filt_ufsdetach(struct knote *); -union _qcvt { - int64_t qcvt; - int32_t val[2]; -}; - -#define SETHIGH(q, h) { \ - union _qcvt tmp; \ - tmp.qcvt = (q); \ - tmp.val[_QUAD_HIGHWORD] = (h); \ - (q) = tmp.qcvt; \ -} -#define SETLOW(q, l) { \ - union _qcvt tmp; \ - tmp.qcvt = (q); \ - tmp.val[_QUAD_LOWWORD] = (l); \ - (q) = tmp.qcvt; \ -} - /* * A virgin directory (no blushing please). */ @@ -1879,8 +1861,8 @@ ufs_vinit(struct mount *mntp, struct vops *specops, struct vops *fifoops, * Initialize modrev times */ getmicrouptime(&mtv); - SETHIGH(ip->i_modrev, mtv.tv_sec); - SETLOW(ip->i_modrev, mtv.tv_usec * 4294); + ip->i_modrev = (u_quad_t)mtv.tv_sec << 32; + ip->i_modrev |= (u_quad_t)mtv.tv_usec * 4294; *vpp = vp; return (0); } |