public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] arch: tile: kernel: setup.c:  Cleaning up missing null-terminate in conjunction with strncpy
@ 2014-07-26 14:04 Rickard Strandqvist
  2014-08-01 20:12 ` Chris Metcalf
  2014-08-05 20:12 ` Chris Metcalf
  0 siblings, 2 replies; 4+ messages in thread
From: Rickard Strandqvist @ 2014-07-26 14:04 UTC (permalink / raw)
  To: Chris Metcalf, Wang Sheng-Hui
  Cc: Rickard Strandqvist, Daniel Walter, linux-kernel

Replacing strncpy with strlcpy to avoid strings that lacks null terminate.

Signed-off-by: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
---
 arch/tile/kernel/setup.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/tile/kernel/setup.c b/arch/tile/kernel/setup.c
index 112abab..1af7d19 100644
--- a/arch/tile/kernel/setup.c
+++ b/arch/tile/kernel/setup.c
@@ -1087,7 +1087,7 @@ static int __init setup_initramfs_file(char *str)
 {
 	if (str == NULL)
 		return -EINVAL;
-	strncpy(initramfs_file, str, sizeof(initramfs_file) - 1);
+	strlcpy(initramfs_file, str, sizeof(initramfs_file));
 	set_initramfs_file = 1;
 
 	return 0;
-- 
1.7.10.4


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

* Re: [PATCH] arch: tile: kernel: setup.c:  Cleaning up missing null-terminate in conjunction with strncpy
  2014-07-26 14:04 [PATCH] arch: tile: kernel: setup.c: Cleaning up missing null-terminate in conjunction with strncpy Rickard Strandqvist
@ 2014-08-01 20:12 ` Chris Metcalf
  2014-08-05 20:12 ` Chris Metcalf
  1 sibling, 0 replies; 4+ messages in thread
From: Chris Metcalf @ 2014-08-01 20:12 UTC (permalink / raw)
  To: Rickard Strandqvist, Wang Sheng-Hui
  Cc: Daniel Walter, linux-kernel, David S. Miller

On 7/26/2014 10:04 AM, Rickard Strandqvist wrote:
> Replacing strncpy with strlcpy to avoid strings that lacks null terminate.
>
> Signed-off-by: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
> ---
>   arch/tile/kernel/setup.c |    2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/tile/kernel/setup.c b/arch/tile/kernel/setup.c
> index 112abab..1af7d19 100644
> --- a/arch/tile/kernel/setup.c
> +++ b/arch/tile/kernel/setup.c
> @@ -1087,7 +1087,7 @@ static int __init setup_initramfs_file(char *str)
>   {
>   	if (str == NULL)
>   		return -EINVAL;
> -	strncpy(initramfs_file, str, sizeof(initramfs_file) - 1);
> +	strlcpy(initramfs_file, str, sizeof(initramfs_file));
>   	set_initramfs_file = 1;
>   
>   	return 0;

Thanks for the patch (this and the one for mpipe.c).  In general I'd rather
check the argument length and return a suitable error rather than using
strlcpy or strncpy to cause a corrupted partial string result.  I've done
this for the examples you pointed to (which I think is everything in arch/tile)
and I'll push those changes up.

-- 
Chris Metcalf, Tilera Corp.
http://www.tilera.com


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

* Re: [PATCH] arch: tile: kernel: setup.c:  Cleaning up missing null-terminate in conjunction with strncpy
  2014-07-26 14:04 [PATCH] arch: tile: kernel: setup.c: Cleaning up missing null-terminate in conjunction with strncpy Rickard Strandqvist
  2014-08-01 20:12 ` Chris Metcalf
@ 2014-08-05 20:12 ` Chris Metcalf
  2014-08-05 20:40   ` Rickard Strandqvist
  1 sibling, 1 reply; 4+ messages in thread
From: Chris Metcalf @ 2014-08-05 20:12 UTC (permalink / raw)
  To: Rickard Strandqvist, Wang Sheng-Hui; +Cc: Daniel Walter, linux-kernel

On 7/26/2014 10:04 AM, Rickard Strandqvist wrote:
> Replacing strncpy with strlcpy to avoid strings that lacks null terminate.
>
> Signed-off-by: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
> ---
>   arch/tile/kernel/setup.c |    2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/tile/kernel/setup.c b/arch/tile/kernel/setup.c
> index 112abab..1af7d19 100644
> --- a/arch/tile/kernel/setup.c
> +++ b/arch/tile/kernel/setup.c
> @@ -1087,7 +1087,7 @@ static int __init setup_initramfs_file(char *str)
>   {
>   	if (str == NULL)
>   		return -EINVAL;
> -	strncpy(initramfs_file, str, sizeof(initramfs_file) - 1);
> +	strlcpy(initramfs_file, str, sizeof(initramfs_file));
>   	set_initramfs_file = 1;
>   
>   	return 0;

I'm inclined not to take this change, because it's not necessary.
The initramfs_file[] is already zero-filled by being in the BSS, and
this is a pretty obscure boot option, so it seems a bit more
maintainable to use a somewhat more standard string API call.

-- 
Chris Metcalf, Tilera Corp.
http://www.tilera.com


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

* Re: [PATCH] arch: tile: kernel: setup.c: Cleaning up missing null-terminate in conjunction with strncpy
  2014-08-05 20:12 ` Chris Metcalf
@ 2014-08-05 20:40   ` Rickard Strandqvist
  0 siblings, 0 replies; 4+ messages in thread
From: Rickard Strandqvist @ 2014-08-05 20:40 UTC (permalink / raw)
  To: Chris Metcalf; +Cc: Wang Sheng-Hui, Daniel Walter, linux-kernel@vger.kernel.org

2014-08-05 22:12 GMT+02:00 Chris Metcalf <cmetcalf@tilera.com>:
> On 7/26/2014 10:04 AM, Rickard Strandqvist wrote:
>>
>> Replacing strncpy with strlcpy to avoid strings that lacks null terminate.
>>
>> Signed-off-by: Rickard Strandqvist
>> <rickard_strandqvist@spectrumdigital.se>
>> ---
>>   arch/tile/kernel/setup.c |    2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/arch/tile/kernel/setup.c b/arch/tile/kernel/setup.c
>> index 112abab..1af7d19 100644
>> --- a/arch/tile/kernel/setup.c
>> +++ b/arch/tile/kernel/setup.c
>> @@ -1087,7 +1087,7 @@ static int __init setup_initramfs_file(char *str)
>>   {
>>         if (str == NULL)
>>                 return -EINVAL;
>> -       strncpy(initramfs_file, str, sizeof(initramfs_file) - 1);
>> +       strlcpy(initramfs_file, str, sizeof(initramfs_file));
>>         set_initramfs_file = 1;
>>         return 0;
>
>
> I'm inclined not to take this change, because it's not necessary.
> The initramfs_file[] is already zero-filled by being in the BSS, and
> this is a pretty obscure boot option, so it seems a bit more
> maintainable to use a somewhat more standard string API call.
>


Hi

Of course this is quite alright, the goal is to create code that it
can not get any bugs.
With sizeof -1 will get it right, if you can only be sure that the
zeroes string will be overwritten.


Kind regards
Rickard Strandqvist

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

end of thread, other threads:[~2014-08-05 20:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-26 14:04 [PATCH] arch: tile: kernel: setup.c: Cleaning up missing null-terminate in conjunction with strncpy Rickard Strandqvist
2014-08-01 20:12 ` Chris Metcalf
2014-08-05 20:12 ` Chris Metcalf
2014-08-05 20:40   ` Rickard Strandqvist

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox