diff options
author | Theodore Ts'o <tytso@mit.edu> | 2021-01-21 23:27:00 -0500 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2021-01-21 23:27:00 -0500 |
commit | c3c41d4ffbdbbce2e7199ece8f76cea0310de820 (patch) | |
tree | a5104cb609a418e38a2edd9237eb81d748fd6f90 | |
parent | 33b0356c353feaef32fdcf300d39d2d2ef08ef1f (diff) | |
download | e2fsprogs-c3c41d4ffbdbbce2e7199ece8f76cea0310de820.tar.gz |
libext2fs: fix UBSAN warning in ext2fs_mmp_new_seq()
Left shifting the pid by 16 bits can cause a UBSAN warning if the pid
is greater than or equal to 2**16. It doesn't matter since we're just
using the pid to seed for a pseudo-random number generator, but
silence the warning by just swapping the high and low 16 bits of the
pid instead.
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
-rw-r--r-- | lib/ext2fs/mmp.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/lib/ext2fs/mmp.c b/lib/ext2fs/mmp.c index e96a22732..223b617d9 100644 --- a/lib/ext2fs/mmp.c +++ b/lib/ext2fs/mmp.c @@ -172,9 +172,11 @@ unsigned ext2fs_mmp_new_seq(void) #ifdef CONFIG_MMP unsigned new_seq; struct timeval tv; + unsigned long pid = getpid(); gettimeofday(&tv, 0); - srand((getpid() << 16) ^ getuid() ^ tv.tv_sec ^ tv.tv_usec); + pid = (pid >> 16) | ((pid & 0xFFFF) << 16); + srand(pid ^ getuid() ^ tv.tv_sec ^ tv.tv_usec); gettimeofday(&tv, 0); /* Crank the random number generator a few times */ |