* [patch] ISDN: pcbit: off by one bugs in pcbit_set_msn()
@ 2014-07-31 15:30 Dan Carpenter
2014-08-01 5:15 ` David Miller
0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2014-07-31 15:30 UTC (permalink / raw)
To: Karsten Keil; +Cc: David S. Miller, Arnd Bergmann, netdev, kernel-janitors
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>
diff --git a/drivers/isdn/pcbit/drv.c b/drivers/isdn/pcbit/drv.c
index f02cc50..4172e22 100644
--- a/drivers/isdn/pcbit/drv.c
+++ b/drivers/isdn/pcbit/drv.c
@@ -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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [patch] ISDN: pcbit: off by one bugs in pcbit_set_msn()
2014-07-31 15:30 [patch] ISDN: pcbit: off by one bugs in pcbit_set_msn() Dan Carpenter
@ 2014-08-01 5:15 ` David Miller
0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2014-08-01 5:15 UTC (permalink / raw)
To: dan.carpenter; +Cc: isdn, arnd, netdev, kernel-janitors
From: Dan Carpenter <dan.carpenter@oracle.com>
Date: Thu, 31 Jul 2014 18:30:11 +0300
> 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>
Applied to net-next, thanks Dan.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-08-01 5:15 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-31 15:30 [patch] ISDN: pcbit: off by one bugs in pcbit_set_msn() Dan Carpenter
2014-08-01 5:15 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).