Skip to content

Commit

Permalink
6lowpan: iphc: Fix an off-by-one check of array index
Browse files Browse the repository at this point in the history
The bounds check of id is off-by-one and the comparison should
be >= rather >. Currently the WARN_ON_ONCE check does not stop
the out of range indexing of &ldev->ctx.table[id] so also add
a return path if the bounds are out of range.

Addresses-Coverity: ("Illegal address computation").
Fixes: 5609c18 ("6lowpan: iphc: add support for stateful compression")
Signed-off-by: Colin Ian King <[email protected]>
Signed-off-by: Marcel Holtmann <[email protected]>
  • Loading branch information
Colin Ian King authored and holtmann committed Jul 22, 2021
1 parent 3735682 commit 9af4176
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion net/6lowpan/debugfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ static void lowpan_dev_debugfs_ctx_init(struct net_device *dev,
struct dentry *root;
char buf[32];

WARN_ON_ONCE(id > LOWPAN_IPHC_CTX_TABLE_SIZE);
if (WARN_ON_ONCE(id >= LOWPAN_IPHC_CTX_TABLE_SIZE))
return;

sprintf(buf, "%d", id);

Expand Down

0 comments on commit 9af4176

Please sign in to comment.