[PATCH] ia32: strncpy does not null terminate string

From: Roel Kluin
Date: Fri Jul 17 2009 - 08:56:23 EST


With `sizeof(lastcomm) - 1` strncpy() will null terminate the string.

Signed-off-by: Roel Kluin <roel.kluin@xxxxxxxxx>
---
To test this:

#include <stdio.h>
#include <string.h>

char a[10];
char b[10];

int main()
{
const char* str = "0123456789012";
strncpy(a, str, sizeof(a));
strncpy(b, str, sizeof(b) - 1);
printf("String a was %s, b was %s\n", a, b);

return 0;
}

Output:
String a was 0123456789012345678, b was 012345678

diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
index 085a8c3..b114f57 100644
--- a/arch/x86/ia32/sys_ia32.c
+++ b/arch/x86/ia32/sys_ia32.c
@@ -687,7 +687,7 @@ long sys32_vm86_warning(void)
compat_printk(KERN_INFO
"%s: vm86 mode not supported on 64 bit kernel\n",
me->comm);
- strncpy(lastcomm, me->comm, sizeof(lastcomm));
+ strncpy(lastcomm, me->comm, sizeof(lastcomm) - 1);
}
return -ENOSYS;
}
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/