Skip to content

Commit 3c0a2e0

Browse files
Sergey ShtylyovTrond Myklebust
Sergey Shtylyov
authored and
Trond Myklebust
committed
nfs: fix undefined behavior in nfs_block_bits()
Shifting *signed int* typed constant 1 left by 31 bits causes undefined behavior. Specify the correct *unsigned long* type by using 1UL instead. Found by Linux Verification Center (linuxtesting.org) with the Svace static analysis tool. Cc: [email protected] Signed-off-by: Sergey Shtylyov <[email protected]> Reviewed-by: Benjamin Coddington <[email protected]> Signed-off-by: Trond Myklebust <[email protected]>
1 parent a01b077 commit 3c0a2e0

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

fs/nfs/internal.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -717,9 +717,9 @@ unsigned long nfs_block_bits(unsigned long bsize, unsigned char *nrbitsp)
717717
if ((bsize & (bsize - 1)) || nrbitsp) {
718718
unsigned char nrbits;
719719

720-
for (nrbits = 31; nrbits && !(bsize & (1 << nrbits)); nrbits--)
720+
for (nrbits = 31; nrbits && !(bsize & (1UL << nrbits)); nrbits--)
721721
;
722-
bsize = 1 << nrbits;
722+
bsize = 1UL << nrbits;
723723
if (nrbitsp)
724724
*nrbitsp = nrbits;
725725
}

0 commit comments

Comments
 (0)