From 67337d7998e9501970901d8d91bc06fe7e69e1a6 Mon Sep 17 00:00:00 2001 From: Joachim Wagner Date: Tue, 1 Sep 2020 13:22:31 +0100 Subject: [PATCH] Correct overflow protection `sizeof()` returns the number of bytes, not bits, and since this is as an unsigned type and the value typically less than 10 the assertion currently does not fail but also fails to detect problems when `MAX_N_BLOCK_ORDER` is too big as the comparison is with the the very big number resulting from an unsigned overflow, typically 2^32-2. --- libprobe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libprobe.c b/libprobe.c index 082f095..a3553d1 100644 --- a/libprobe.c +++ b/libprobe.c @@ -690,7 +690,7 @@ uint64_t probe_device_max_blocks(struct device *dev) /* Make sure that there is no overflow in the formula below. * The number 10 is arbitrary here, that is, it's not tight. */ - assert(MAX_N_BLOCK_ORDER < sizeof(int) - 10); + assert(MAX_N_BLOCK_ORDER < 8*sizeof(int) - 10); return /* find_cache_size() */