]> git.ipfire.org Git - thirdparty/util-linux.git/commit
libblkid: fix time_t handling
authorSamanta Navarro <ferivoz@riseup.net>
Sun, 8 Nov 2020 11:46:56 +0000 (11:46 +0000)
committerSamanta Navarro <ferivoz@riseup.net>
Tue, 10 Nov 2020 11:52:45 +0000 (11:52 +0000)
commit3fbeb9eeb86a04283e38ee9272a7726e7fbb8de9
tree971ba90b02703478da8b1cd757bb1bfecc5c632e
parent8f22adaaf30e9fd3bf83da0213b4a6525c9305cd
libblkid: fix time_t handling

The time_t data type is a signed integer. A signed integer overflow is
not defined in C programming language.

A signed overflow occurs on 32 bit systems with 32 time_t for loop back
devices, e.g. when calling "blkid /dev/loop0". This happens because
bid_time is set to INT_MIN and the diff calculation cannot store the
result in time_t (positive int - INT_MIN > INT_MAX).

This fix changes the code to use an unsigned integer calculation. It
pretty much means that the code works as before, but well defined in C.
Checking diff to be positive protects the code against system setups
with dates before 1970 as well.

The time_t data type on modern Linux systems is 64 bit even for 32 bit
systems. Since long is 32 bit on these systems, long long is a better
data type for 64 bit output.

Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
libblkid/src/dev.c
libblkid/src/devname.c
libblkid/src/save.c
libblkid/src/verify.c