From patchwork Thu Dec 13 22:04:27 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [5/8] e2fsck/revoke.c: Fix undefined behavior in hash() Date: Thu, 13 Dec 2012 12:04:27 -0000 From: Sami Liedes X-Patchwork-Id: 206258 Message-Id: <20121213220426.GM9713@sli.dy.fi> To: linux-ext4@vger.kernel.org There's a shift by (hash_shift - 12) in hash(), but hash() is called with hash_shift=10, resulting in a negative shift and thus undefined behavior. A simple and stupid minimal fix is to just change the subtracted amount to 10. Caught by clang -fsanitize=undefined. Signed-off-by: Sami Liedes --- e2fsck/revoke.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2fsck/revoke.c b/e2fsck/revoke.c index 38c265e..dddef4d 100644 --- a/e2fsck/revoke.c +++ b/e2fsck/revoke.c @@ -115,7 +115,7 @@ static inline int hash(journal_t *journal, unsigned long block) return ((block << (hash_shift - 6)) ^ (block >> 13) ^ - (block << (hash_shift - 12))) & (table->hash_size - 1); + (block << (hash_shift - 10))) & (table->hash_size - 1); } static int insert_revoke_hash(journal_t *journal, unsigned long blocknr,