Skip to content

Commit

Permalink
ndctl/namespace.c: fix a potential integer overflow
Browse files Browse the repository at this point in the history
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.

Reviewed-by: Dan Williams <[email protected]>
Signed-off-by: Vishal Verma <[email protected]>
  • Loading branch information
stellarhopper committed May 10, 2019
1 parent df989d9 commit d2cf460
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion ndctl/namespace.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit d2cf460

Please sign in to comment.