From ec1c87f84bc4b3ca60c422f02c08b0e4e0543bd6 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Tue, 23 Apr 2024 22:13:25 -0400 Subject: Fix coverity false positives introduced by the post-2038 changes Commit ca8bc9240a00 ("Add post-2038 timestamp support...") did things like casting a 64-bit unsigned integer into a signed 32-bit integer deliberately; but Coverity thinks this is a bug. So mask off the bits to make it clear this was deliberate. Addresses-Coverity-Bug: 1596519 Addresses-Coverity-Bug: 1596515 Addresses-Coverity-Bug: 1596514 Addresses-Coverity-Bug: 1596513 Addresses-Coverity-Bug: 1596511 Addresses-Coverity-Bug: 1596509 Addresses-Coverity-Bug: 1596508 Addresses-Coverity-Bug: 1596504 Addresses-Coverity-Bug: 1596502 Addresses-Coverity-Bug: 1596501 Signed-off-by: Theodore Ts'o --- lib/ext2fs/ext2fs.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h index 9ecbb50ba..a3259136b 100644 --- a/lib/ext2fs/ext2fs.h +++ b/lib/ext2fs/ext2fs.h @@ -584,7 +584,8 @@ static inline __u32 __encode_extra_time(time_t seconds, __u32 nsec) __u32 extra = 0; #if (SIZEOF_TIME_T > 4) - extra = ((seconds - (__s32)seconds) >> 32) & EXT4_EPOCH_MASK; + extra = ((seconds - (__s32)(seconds & 0xffffffff)) >> 32) & + EXT4_EPOCH_MASK; #endif return extra | (nsec << EXT4_EPOCH_BITS); } @@ -610,7 +611,7 @@ static inline __u32 __decode_extra_nsec(__u32 extra) do { \ if (ext2fs_inode_includes(ext2fs_inode_actual_size(inode), \ field ## _extra)) { \ - (inode)->field = (__s32)sec; \ + (inode)->field = (__s32)(sec & 0xfffffff); \ ((struct ext2_inode_large *)(inode))->field ## _extra = \ __encode_extra_time(sec, 0); \ } else { \ @@ -627,7 +628,7 @@ static inline void __sb_set_tstamp(__u32 *lo, __u8 *hi, time_t seconds) { *lo = seconds & 0xffffffff; #if (SIZEOF_TIME_T > 4) - *hi = seconds >> 32; + *hi = (seconds >> 32) & EXT4_EPOCH_MASK; #else *hi = 0; #endif -- cgit 1.2.3-korg