All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] powerpc/cell: strncpy does not null terminate string
@ 2009-07-17 12:41 Roel Kluin
  2009-07-17 14:27 ` Roel Kluin
                   ` (6 more replies)
  0 siblings, 7 replies; 14+ messages in thread
From: Roel Kluin @ 2009-07-17 12:41 UTC (permalink / raw)
  To: arnd, linuxppc-dev, cbe-oss-dev, Andrew Morton

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

Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
---
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/powerpc/platforms/cell/celleb_setup.c b/arch/powerpc/platforms/cell/celleb_setup.c
index 07c234f..cfdbadb 100644
--- a/arch/powerpc/platforms/cell/celleb_setup.c
+++ b/arch/powerpc/platforms/cell/celleb_setup.c
@@ -80,7 +80,7 @@ static void celleb_show_cpuinfo(struct seq_file *m)
 
 static int __init celleb_machine_type_hack(char *ptr)
 {
-	strncpy(celleb_machine_type, ptr, sizeof(celleb_machine_type));
+	strncpy(celleb_machine_type, ptr, sizeof(celleb_machine_type) - 1);
 	celleb_machine_type[sizeof(celleb_machine_type)-1] = 0;
 	return 0;
 }

^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2009-07-22 12:29 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-17 12:41 [PATCH] powerpc/cell: strncpy does not null terminate string Roel Kluin
2009-07-17 14:27 ` Roel Kluin
2009-07-17 15:56   ` Arnd Bergmann
2009-07-21  9:31     ` Ken Kawakami
2009-07-17 15:05 ` Arnd Bergmann
2009-07-17 15:19   ` roel kluin
2009-07-17 15:35 ` [PATCH] dm: " Roel Kluin
2009-07-22 12:29   ` Alasdair G Kergon
2009-07-17 15:41 ` [PATCH] media: " Roel Kluin
2009-07-17 15:54 ` Roel Kluin
2009-07-17 18:01 ` [PATCH] b44: " Roel Kluin
2009-07-20 15:04   ` David Miller
2009-07-21 10:17 ` [PATCH] powerpc/cell: replace strncpy by strlcpy Roel Kluin
2009-07-22  4:22   ` Ken Kawakami

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.