Patchwork [5/8] e2fsck/revoke.c: Fix undefined behavior in hash()

login
register
mail settings
Submitter Sami Liedes
Date Dec. 13, 2012, 10:04 p.m.
Message ID <20121213220426.GM9713@sli.dy.fi>
Download mbox | patch
Permalink /patch/206258/
State New
Headers show

Comments

Sami Liedes - Dec. 13, 2012, 10:04 p.m.
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 <sami.liedes@iki.fi>
---
 e2fsck/revoke.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Patch

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,