diff mbox series

[ndctl,4/4] ndctl/namespace.c: Fix a potential integer overflow

Message ID 20190510190839.29637-5-vishal.l.verma@intel.com (mailing list archive)
State Accepted
Commit d2cf4605c58cbdfe9040f76a867b8d7d7c826e8d
Headers show
Series static analysis fixes | expand

Commit Message

Verma, Vishal L May 10, 2019, 7:08 p.m. UTC
Static analysis warns that we may cause an integer overflow when
left-shifting bb->len in nstype_clear_badblocks(). While it is unlikely
to trigger this in real-world usage, since bb->len is limited by the
kernel, the fix is is a trivial cast, and it quells the warning, and
increases our robustness.

Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
---
 ndctl/namespace.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/ndctl/namespace.c b/ndctl/namespace.c
index 31e6ecd..58a9e3c 100644
--- a/ndctl/namespace.c
+++ b/ndctl/namespace.c
@@ -1146,7 +1146,7 @@  static int nstype_clear_badblocks(struct ndctl_namespace *ndns,
 		unsigned long long bb_begin, bb_end, bb_len;
 
 		bb_begin = region_begin + (bb->offset << 9);
-		bb_len = bb->len << 9;
+		bb_len = (unsigned long long)bb->len << 9;
 		bb_end = bb_begin + bb_len - 1;
 
 		/* bb is not fully contained in the usable area */