aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2024-04-23 22:13:25 -0400
committerTheodore Ts'o <tytso@mit.edu>2024-04-23 22:13:25 -0400
commitec1c87f84bc4b3ca60c422f02c08b0e4e0543bd6 (patch)
tree09a6ebae08eee8203b03d43b6a9731b878f2ce93
parenta12302fa683e397a731e679bd1b818c45ad3ff78 (diff)
downloade2fsprogs-ec1c87f84bc4b3ca60c422f02c08b0e4e0543bd6.tar.gz
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 <tytso@mit.edu>
-rw-r--r--lib/ext2fs/ext2fs.h7
1 files 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