Skip to content

Commit

Permalink
isdn: icn: Fix potentially wrong string handling
Browse files Browse the repository at this point in the history
This warning was reported by cppcheck:
drivers/isdn/icn/icn.c:1641: error: Dangerous usage of 'rev' (strncpy doesn't always 0-terminate it)

If strncpy copied 20 bytes, the destination string rev was not terminated.
The patch adds one more byte to rev and makes sure that this byte is
always 0.

Cc: Karsten Keil <isdn@linux-pingi.de>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Tejun Heo <tj@kernel.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: netdev@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Stefan Weil <weil@mail.berlios.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Stefan Weil authored and David S. Miller committed Feb 1, 2011
1 parent d9c8f49 commit a29ae23
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion drivers/isdn/icn/icn.c
Original file line number Diff line number Diff line change
Expand Up @@ -1627,7 +1627,7 @@ __setup("icn=", icn_setup);
static int __init icn_init(void)
{
char *p;
char rev[20];
char rev[21];

memset(&dev, 0, sizeof(icn_dev));
dev.memaddr = (membase & 0x0ffc000);
Expand All @@ -1638,6 +1638,7 @@ static int __init icn_init(void)

if ((p = strchr(revision, ':'))) {
strncpy(rev, p + 1, 20);
rev[20] = '\0';
p = strchr(rev, '$');
if (p)
*p = 0;
Expand Down

0 comments on commit a29ae23

Please sign in to comment.