* [PATCH] misc: ti-st: st_kim.c: Cleaning up missing null-terminate after strncpy call
@ 2014-08-09 23:45 Rickard Strandqvist
2014-08-11 1:01 ` Mark D Rustad
0 siblings, 1 reply; 4+ messages in thread
From: Rickard Strandqvist @ 2014-08-09 23:45 UTC (permalink / raw)
To: Rickard Strandqvist, Andrew Morton
Cc: Greg Kroah-Hartman, Linus Walleij, Wolfram Sang, Peter Hurley,
linux-kernel
Added a guaranteed null-terminate after call to strncpy.
Signed-off-by: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
---
drivers/misc/ti-st/st_kim.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/misc/ti-st/st_kim.c b/drivers/misc/ti-st/st_kim.c
index 9d3dbb2..bce4468 100644
--- a/drivers/misc/ti-st/st_kim.c
+++ b/drivers/misc/ti-st/st_kim.c
@@ -593,6 +593,7 @@ static ssize_t store_dev_name(struct device *dev,
struct kim_data_s *kim_data = dev_get_drvdata(dev);
pr_debug("storing dev name >%s<", buf);
strncpy(kim_data->dev_name, buf, count);
+ kim_data->dev_name[count - 1] = '\n';
pr_debug("stored dev name >%s<", kim_data->dev_name);
return count;
}
--
1.7.10.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] misc: ti-st: st_kim.c: Cleaning up missing null-terminate after strncpy call
2014-08-09 23:45 [PATCH] misc: ti-st: st_kim.c: Cleaning up missing null-terminate after strncpy call Rickard Strandqvist
@ 2014-08-11 1:01 ` Mark D Rustad
2014-08-11 9:14 ` Wolfram Sang
0 siblings, 1 reply; 4+ messages in thread
From: Mark D Rustad @ 2014-08-11 1:01 UTC (permalink / raw)
To: Rickard Strandqvist
Cc: Andrew Morton, Greg Kroah-Hartman, Linus Walleij, Wolfram Sang,
Peter Hurley, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 987 bytes --]
On Aug 9, 2014, at 4:45 PM, Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se> wrote:
> Added a guaranteed null-terminate after call to strncpy.
>
> Signed-off-by: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
> ---
> drivers/misc/ti-st/st_kim.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/misc/ti-st/st_kim.c b/drivers/misc/ti-st/st_kim.c
> index 9d3dbb2..bce4468 100644
> --- a/drivers/misc/ti-st/st_kim.c
> +++ b/drivers/misc/ti-st/st_kim.c
> @@ -593,6 +593,7 @@ static ssize_t store_dev_name(struct device *dev,
> struct kim_data_s *kim_data = dev_get_drvdata(dev);
> pr_debug("storing dev name >%s<", buf);
> strncpy(kim_data->dev_name, buf, count);
> + kim_data->dev_name[count - 1] = '\n';
Of course this does not add termination, but adds a newline at the end of the buffer? Huh?
> pr_debug("stored dev name >%s<", kim_data->dev_name);
> return count;
> }
--
Mark Rustad, MRustad@gmail.com
[-- Attachment #2: Message signed with OpenPGP using GPGMail --]
[-- Type: application/pgp-signature, Size: 841 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] misc: ti-st: st_kim.c: Cleaning up missing null-terminate after strncpy call
2014-08-11 1:01 ` Mark D Rustad
@ 2014-08-11 9:14 ` Wolfram Sang
2014-08-11 19:45 ` Rickard Strandqvist
0 siblings, 1 reply; 4+ messages in thread
From: Wolfram Sang @ 2014-08-11 9:14 UTC (permalink / raw)
To: Mark D Rustad
Cc: Rickard Strandqvist, Andrew Morton, Greg Kroah-Hartman,
Linus Walleij, Peter Hurley, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 206 bytes --]
> > strncpy(kim_data->dev_name, buf, count);
> > + kim_data->dev_name[count - 1] = '\n';
>
> Of course this does not add termination, but adds a newline at the end of the buffer? Huh?
strlcpy?
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] misc: ti-st: st_kim.c: Cleaning up missing null-terminate after strncpy call
2014-08-11 9:14 ` Wolfram Sang
@ 2014-08-11 19:45 ` Rickard Strandqvist
0 siblings, 0 replies; 4+ messages in thread
From: Rickard Strandqvist @ 2014-08-11 19:45 UTC (permalink / raw)
To: Wolfram Sang
Cc: Mark D Rustad, Andrew Morton, Greg Kroah-Hartman, Linus Walleij,
Peter Hurley, linux-kernel
2014-08-11 11:14 GMT+02:00 Wolfram Sang <wsa@the-dreams.de>:
>
>> > strncpy(kim_data->dev_name, buf, count);
>> > + kim_data->dev_name[count - 1] = '\n';
>>
>> Of course this does not add termination, but adds a newline at the end of the buffer? Huh?
>
> strlcpy?
>
Hi Wolfram
Sure, strlcpy is preferable in many ways if we only can guarantee that
it is safe.
I have seldom been so much criticism when I start switching to
strlcpy, although much of it was justified :)
Even Linus was getting into the debate. See more:
https://plus.google.com/111049168280159033135/posts/1amLbuhWbh5
I do this only when I'm sure it will not cause any other problems.
But if you or anyone else can guarantee that in this case, so I'd make
a new patch.
Kind regards
Rickard Strandqvist
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-08-11 19:46 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-09 23:45 [PATCH] misc: ti-st: st_kim.c: Cleaning up missing null-terminate after strncpy call Rickard Strandqvist
2014-08-11 1:01 ` Mark D Rustad
2014-08-11 9:14 ` Wolfram Sang
2014-08-11 19:45 ` Rickard Strandqvist
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.