* [PATCH] PPC: in celleb_show_cpuinfo() convert strncpy(x, y, sizeof(x)) to strlcpy
@ 2008-03-06 13:16 Roel Kluin
2008-03-06 13:20 ` Roel Kluin
2008-03-06 15:44 ` Segher Boessenkool
0 siblings, 2 replies; 4+ messages in thread
From: Roel Kluin @ 2008-03-06 13:16 UTC (permalink / raw)
To: paulus, arnd; +Cc: linuxppc-dev, lkml
This patch was not yet tested. Please confirm it's right.
---
strncpy does not append '\0' if the length of the source string equals
the size parameter, strlcpy does.
Signed-off-by: Roel Kluin <12o3l@tiscali.nl>
---
diff --git a/arch/powerpc/platforms/celleb/setup.c b/arch/powerpc/platforms/celleb/setup.c
index f27ae1e..d70fc53 100644
--- a/arch/powerpc/platforms/celleb/setup.c
+++ b/arch/powerpc/platforms/celleb/setup.c
@@ -81,7 +81,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;
}
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] PPC: in celleb_show_cpuinfo() convert strncpy(x, y, sizeof(x)) to strlcpy
2008-03-06 13:16 [PATCH] PPC: in celleb_show_cpuinfo() convert strncpy(x, y, sizeof(x)) to strlcpy Roel Kluin
@ 2008-03-06 13:20 ` Roel Kluin
2008-03-07 8:06 ` Ishizaki Kou
2008-03-06 15:44 ` Segher Boessenkool
1 sibling, 1 reply; 4+ messages in thread
From: Roel Kluin @ 2008-03-06 13:20 UTC (permalink / raw)
To: paulus, arnd; +Cc: linuxppc-dev, lkml
Roel Kluin wrote:
> This patch was not yet tested. Please confirm it's right.
was too quick with the send button. the batch below is probably better
---
strncpy does not append '\0' if the length of the source string equals
the size parameter, strlcpy does.
Signed-off-by: Roel Kluin <12o3l@tiscali.nl>
---
diff --git a/arch/powerpc/platforms/celleb/setup.c b/arch/powerpc/platforms/celleb/setup.c
index f27ae1e..cbe09d9 100644
--- a/arch/powerpc/platforms/celleb/setup.c
+++ b/arch/powerpc/platforms/celleb/setup.c
@@ -81,8 +81,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));
- celleb_machine_type[sizeof(celleb_machine_type)-1] = 0;
+ strlcpy(celleb_machine_type, ptr, sizeof(celleb_machine_type));
return 0;
}
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] PPC: in celleb_show_cpuinfo() convert strncpy(x, y, sizeof(x)) to strlcpy
2008-03-06 13:20 ` Roel Kluin
@ 2008-03-07 8:06 ` Ishizaki Kou
0 siblings, 0 replies; 4+ messages in thread
From: Ishizaki Kou @ 2008-03-07 8:06 UTC (permalink / raw)
To: paulus; +Cc: linuxppc-dev, 12o3l, linux-kernel, arnd
Roel Kluin <12o3l@tiscali.nl> wrote:
> Roel Kluin wrote:
> > This patch was not yet tested. Please confirm it's right.
>
> was too quick with the send button. the batch below is probably better
> ---
> strncpy does not append '\0' if the length of the source string equals
> the size parameter, strlcpy does.
>
> Signed-off-by: Roel Kluin <12o3l@tiscali.nl>
Acked-by: Kou Ishizaki <kou.ishizaki@toshiba.co.jp>
I tested Roel's 2nd patch and it works good on Celleb.
> ---
> diff --git a/arch/powerpc/platforms/celleb/setup.c b/arch/powerpc/platforms/celleb/setup.c
> index f27ae1e..cbe09d9 100644
> --- a/arch/powerpc/platforms/celleb/setup.c
> +++ b/arch/powerpc/platforms/celleb/setup.c
> @@ -81,8 +81,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));
> - celleb_machine_type[sizeof(celleb_machine_type)-1] = 0;
> + strlcpy(celleb_machine_type, ptr, sizeof(celleb_machine_type));
> return 0;
> }
>
> _______________________________________________
> Linuxppc-dev mailing list
> Linuxppc-dev@ozlabs.org
> https://ozlabs.org/mailman/listinfo/linuxppc-dev
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] PPC: in celleb_show_cpuinfo() convert strncpy(x, y, sizeof(x)) to strlcpy
2008-03-06 13:16 [PATCH] PPC: in celleb_show_cpuinfo() convert strncpy(x, y, sizeof(x)) to strlcpy Roel Kluin
2008-03-06 13:20 ` Roel Kluin
@ 2008-03-06 15:44 ` Segher Boessenkool
1 sibling, 0 replies; 4+ messages in thread
From: Segher Boessenkool @ 2008-03-06 15:44 UTC (permalink / raw)
To: Roel Kluin; +Cc: linuxppc-dev, paulus, lkml, arnd
> This patch was not yet tested. Please confirm it's right.
> ---
> strncpy does not append '\0' if the length of the source string equals
> the size parameter, strlcpy does.
strlcpy() doesn't fill the rest of the array with zeroes, strncpy()
does. This could matter (information leak, for example), although
I doubt it does here.
> - 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;
That last statement makes the strncpy() case always zero-terminated,
so this patch isn't necessary. Oh, and neither the old nor the new
code handles the case where the string doesn't fit (other than just
cutting it short); is that the wanted behaviour?
Segher
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2008-03-07 8:06 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-03-06 13:16 [PATCH] PPC: in celleb_show_cpuinfo() convert strncpy(x, y, sizeof(x)) to strlcpy Roel Kluin
2008-03-06 13:20 ` Roel Kluin
2008-03-07 8:06 ` Ishizaki Kou
2008-03-06 15:44 ` Segher Boessenkool
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).