Skip to content

Commit

Permalink
ISDN: pcbit: off by one bugs in pcbit_set_msn()
Browse files Browse the repository at this point in the history
1) We don't allocate enough space for the NUL terminator so we end up
   corrupting one character beyond the end of the buffer.

2) The "len - 1" should just be "len".  The code is trying to copy a
   word from a buffer up to a comma or the last word in the buffer.
   Say you have the buffer, "foo,bar,baz", then this code truncates the
   last letter off each word so you get "fo", "ba", and "ba".  You would
   hope this kind of bug would get noticed in testing...

   I'm not very familiar with this code and I can't test it, but I think
   we should copy the final character.

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 Aug 1, 2014
1 parent e98d69b commit 7bcc673
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions drivers/isdn/pcbit/drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -1035,14 +1035,14 @@ static void pcbit_set_msn(struct pcbit_dev *dev, char *list)
}
ptr->next = NULL;

ptr->msn = kmalloc(len, GFP_ATOMIC);
ptr->msn = kmalloc(len + 1, GFP_ATOMIC);
if (!ptr->msn) {
printk(KERN_WARNING "kmalloc failed\n");
kfree(ptr);
return;
}

memcpy(ptr->msn, sp, len - 1);
memcpy(ptr->msn, sp, len);
ptr->msn[len] = 0;

#ifdef DEBUG
Expand Down

0 comments on commit 7bcc673

Please sign in to comment.