Skip to content

Commit

Permalink
isdn/kcapi: fix a small underflow
Browse files Browse the repository at this point in the history
In get_capi_ctr_by_nr() and get_capi_appl_by_nr() the parameter comes
from skb->data.  The current code can underflow to one space before the
start of the array.

The sanity check isn't needed in __get_capi_appl_by_nr() but I changed
it to match the others.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Dan Carpenter authored and David S. Miller committed May 20, 2013
1 parent 057cf65 commit 25dff94
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions drivers/isdn/capi/kcapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ capi_ctr_put(struct capi_ctr *ctr)

static inline struct capi_ctr *get_capi_ctr_by_nr(u16 contr)
{
if (contr - 1 >= CAPI_MAXCONTR)
if (contr < 1 || contr - 1 >= CAPI_MAXCONTR)
return NULL;

return capi_controller[contr - 1];
Expand All @@ -103,15 +103,15 @@ static inline struct capi20_appl *__get_capi_appl_by_nr(u16 applid)
{
lockdep_assert_held(&capi_controller_lock);

if (applid - 1 >= CAPI_MAXAPPL)
if (applid < 1 || applid - 1 >= CAPI_MAXAPPL)
return NULL;

return capi_applications[applid - 1];
}

static inline struct capi20_appl *get_capi_appl_by_nr(u16 applid)
{
if (applid - 1 >= CAPI_MAXAPPL)
if (applid < 1 || applid - 1 >= CAPI_MAXAPPL)
return NULL;

return rcu_dereference(capi_applications[applid - 1]);
Expand Down

0 comments on commit 25dff94

Please sign in to comment.