Skip to content

Commit

Permalink
staging/slicoss: Fix buffer possible overflow in slic_card_locate
Browse files Browse the repository at this point in the history
smatch complains about a possible buffer overflow
slicoss.c:3651 slic_card_locate() error: buffer overflow
'physcard->adapter' 4 <= 4

If the for loop is not exited prematurely i++ is executed after the last
iteration and thus i can be 4, which is out of bounds for
physcard->adapter.

-> Add check for this condition and simplify the if statement by
inverting the condition.

Signed-off-by: Peter Huewe <peterhuewe@gmx.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Peter Huewe authored and Greg Kroah-Hartman committed Mar 11, 2013
1 parent 6d1b80f commit 20d403e
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions drivers/staging/slicoss/slicoss.c
Original file line number Diff line number Diff line change
Expand Up @@ -3643,11 +3643,12 @@ static u32 slic_card_locate(struct adapter *adapter)

while (physcard) {
for (i = 0; i < SLIC_MAX_PORTS; i++) {
if (!physcard->adapter[i])
continue;
else
if (physcard->adapter[i])
break;
}
if (i == SLIC_MAX_PORTS)
break;

if (physcard->adapter[i]->slotnumber == adapter->slotnumber)
break;
physcard = physcard->next;
Expand Down

0 comments on commit 20d403e

Please sign in to comment.