diff mbox

powerpc/cell: strncpy does not null terminate string

Message ID 4A608A69.4060204@gmail.com
State Changes Requested
Headers show

Commit Message

roel kluin July 17, 2009, 2:27 p.m. UTC
strlcpy() will always null terminate the string.

Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
---
Please use this one instead

Comments

Arnd Bergmann July 17, 2009, 3:56 p.m. UTC | #1
On Friday 17 July 2009, Roel Kluin wrote:
> 
>  static int __init celleb_machine_type_hack(char *ptr)
>  {
> -       strncpy(celleb_machine_type, ptr, sizeof(celleb_machine_type));
> +       strlcpy(celleb_machine_type, ptr, sizeof(celleb_machine_type));
>         celleb_machine_type[sizeof(celleb_machine_type)-1] = 0;
>         return 0;

This still is pointless as long as you keep the explicit null-termination
in the next line, the patch still doesn't change anything significant.

The file is maintained by Ishizaki Kou, if he would prefer to take a
patch replacing the two lines with one, that's fine with me, otherwise
I just wouldn't bother. You still only gain a few bytes of inittext, but
that is discarded at boot time.

	Arnd <><
Ken Kawakami July 21, 2009, 9:31 a.m. UTC | #2
Arnd-san, Roel-san,

Thanks for pointing us to the redundant cord portion.

> On Friday 17 July 2009, Roel Kluin wrote:
> > 
> >  static int __init celleb_machine_type_hack(char *ptr)
> >  {
> > -       strncpy(celleb_machine_type, ptr, sizeof(celleb_machine_type));
> > +       strlcpy(celleb_machine_type, ptr, sizeof(celleb_machine_type));
> >         celleb_machine_type[sizeof(celleb_machine_type)-1] = 0;
> >         return 0;
> 
> This still is pointless as long as you keep the explicit null-termination
> in the next line, the patch still doesn't change anything significant.
> 
> The file is maintained by Ishizaki Kou, if he would prefer to take a
> patch replacing the two lines with one, that's fine with me, otherwise
> I just wouldn't bother. You still only gain a few bytes of inittext, but
> that is discarded at boot time.

We prefer to take the patch which is replacing the two lines with one.
-       strncpy(celleb_machine_type, ptr, sizeof(celleb_machine_type));
+       strlcpy(celleb_machine_type, ptr, sizeof(celleb_machine_type));
-       celleb_machine_type[sizeof(celleb_machine_type)-1] = 0;

Thanks,
Ken Kawakami
diff mbox

Patch

diff --git a/arch/powerpc/platforms/cell/celleb_setup.c b/arch/powerpc/platforms/cell/celleb_setup.c
index 07c234f..1896cd8 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));
+	strlcpy(celleb_machine_type, ptr, sizeof(celleb_machine_type));
 	celleb_machine_type[sizeof(celleb_machine_type)-1] = 0;
 	return 0;
 }