Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ISDN: pcbit: off by one bugs in pcbit_set_msn()

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>

authored by

Dan Carpenter and committed by
David S. Miller
7bcc6738 e98d69ba

+2 -2
+2 -2
drivers/isdn/pcbit/drv.c
··· 1035 1035 } 1036 1036 ptr->next = NULL; 1037 1037 1038 - ptr->msn = kmalloc(len, GFP_ATOMIC); 1038 + ptr->msn = kmalloc(len + 1, GFP_ATOMIC); 1039 1039 if (!ptr->msn) { 1040 1040 printk(KERN_WARNING "kmalloc failed\n"); 1041 1041 kfree(ptr); 1042 1042 return; 1043 1043 } 1044 1044 1045 - memcpy(ptr->msn, sp, len - 1); 1045 + memcpy(ptr->msn, sp, len); 1046 1046 ptr->msn[len] = 0; 1047 1047 1048 1048 #ifdef DEBUG