public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH linux-next v2] parisc: use strscpy() to instead of strncpy()
@ 2022-12-26 10:40 yang.yang29
  2022-12-27  7:47 ` Rolf Eike Beer
  0 siblings, 1 reply; 3+ messages in thread
From: yang.yang29 @ 2022-12-26 10:40 UTC (permalink / raw)
  To: james.bottomley; +Cc: deller, linux-parisc, linux-kernel, xu.panda, yang.yang29

From: Xu Panda <xu.panda@zte.com.cn>

The implementation of strscpy() is more robust and safer.
That's now the recommended way to copy NUL-terminated strings.

Signed-off-by: Xu Panda <xu.panda@zte.com.cn>
Signed-off-by: Yang Yang <yang.yang29@zte.com>
---
change for v2
 - sizeof(in) is better and simplified, thanks for Helge Deller.
---
 drivers/parisc/pdc_stable.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/parisc/pdc_stable.c b/drivers/parisc/pdc_stable.c
index d6af5726ddf3..d3075445260b 100644
--- a/drivers/parisc/pdc_stable.c
+++ b/drivers/parisc/pdc_stable.c
@@ -274,8 +274,7 @@ pdcspath_hwpath_write(struct pdcspath_entry *entry, const char *buf, size_t coun

 	/* We'll use a local copy of buf */
 	count = min_t(size_t, count, sizeof(in)-1);
-	strncpy(in, buf, count);
-	in[count] = '\0';
+	strscpy(in, buf, sizeof(in));
 	
 	/* Let's clean up the target. 0xff is a blank pattern */
 	memset(&hwpath, 0xff, sizeof(hwpath));
@@ -388,8 +387,7 @@ pdcspath_layer_write(struct pdcspath_entry *entry, const char *buf, size_t count

 	/* We'll use a local copy of buf */
 	count = min_t(size_t, count, sizeof(in)-1);
-	strncpy(in, buf, count);
-	in[count] = '\0';
+	strscpy(in, buf, sizeof(in));
 	
 	/* Let's clean up the target. 0 is a blank pattern */
 	memset(&layers, 0, sizeof(layers));
@@ -756,8 +754,7 @@ static ssize_t pdcs_auto_write(struct kobject *kobj,

 	/* We'll use a local copy of buf */
 	count = min_t(size_t, count, sizeof(in)-1);
-	strncpy(in, buf, count);
-	in[count] = '\0';
+	strscpy(in, buf, sizeof(in));

 	/* Current flags are stored in primary boot path entry */
 	pathentry = &pdcspath_entry_primary;
-- 
2.15.2

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

* Re: [PATCH linux-next v2] parisc: use strscpy() to instead of strncpy()
  2022-12-26 10:40 [PATCH linux-next v2] parisc: use strscpy() to instead of strncpy() yang.yang29
@ 2022-12-27  7:47 ` Rolf Eike Beer
  2022-12-27 21:30   ` Helge Deller
  0 siblings, 1 reply; 3+ messages in thread
From: Rolf Eike Beer @ 2022-12-27  7:47 UTC (permalink / raw)
  To: james.bottomley, yang.yang29
  Cc: deller, linux-parisc, linux-kernel, xu.panda, yang.yang29

[-- Attachment #1: Type: text/plain, Size: 1101 bytes --]

Am Montag, 26. Dezember 2022, 11:40:04 CET schrieb yang.yang29@zte.com.cn:
> From: Xu Panda <xu.panda@zte.com.cn>
> 
> The implementation of strscpy() is more robust and safer.
> That's now the recommended way to copy NUL-terminated strings.
> 
> Signed-off-by: Xu Panda <xu.panda@zte.com.cn>
> Signed-off-by: Yang Yang <yang.yang29@zte.com>
> ---
> change for v2
>  - sizeof(in) is better and simplified, thanks for Helge Deller.
> ---
>  drivers/parisc/pdc_stable.c | 9 +++------
>  1 file changed, 3 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/parisc/pdc_stable.c b/drivers/parisc/pdc_stable.c
> index d6af5726ddf3..d3075445260b 100644
> --- a/drivers/parisc/pdc_stable.c
> +++ b/drivers/parisc/pdc_stable.c
> @@ -274,8 +274,7 @@ pdcspath_hwpath_write(struct pdcspath_entry *entry,
> const char *buf, size_t coun
> 
>  	/* We'll use a local copy of buf */
>  	count = min_t(size_t, count, sizeof(in)-1);
> -	strncpy(in, buf, count);
> -	in[count] = '\0';
> +	strscpy(in, buf, sizeof(in));

What is "count" now needed for? Looks like a write only variable at least in 
these hunks.

Eike

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

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

* Re: [PATCH linux-next v2] parisc: use strscpy() to instead of strncpy()
  2022-12-27  7:47 ` Rolf Eike Beer
@ 2022-12-27 21:30   ` Helge Deller
  0 siblings, 0 replies; 3+ messages in thread
From: Helge Deller @ 2022-12-27 21:30 UTC (permalink / raw)
  To: Rolf Eike Beer, james.bottomley, yang.yang29
  Cc: linux-parisc, linux-kernel, xu.panda

On 12/27/22 08:47, Rolf Eike Beer wrote:
> Am Montag, 26. Dezember 2022, 11:40:04 CET schrieb yang.yang29@zte.com.cn:
>> From: Xu Panda <xu.panda@zte.com.cn>
>>
>> The implementation of strscpy() is more robust and safer.
>> That's now the recommended way to copy NUL-terminated strings.
>>
>> Signed-off-by: Xu Panda <xu.panda@zte.com.cn>
>> Signed-off-by: Yang Yang <yang.yang29@zte.com>
>> ---
>> change for v2
>>   - sizeof(in) is better and simplified, thanks for Helge Deller.
>> ---
>>   drivers/parisc/pdc_stable.c | 9 +++------
>>   1 file changed, 3 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/parisc/pdc_stable.c b/drivers/parisc/pdc_stable.c
>> index d6af5726ddf3..d3075445260b 100644
>> --- a/drivers/parisc/pdc_stable.c
>> +++ b/drivers/parisc/pdc_stable.c
>> @@ -274,8 +274,7 @@ pdcspath_hwpath_write(struct pdcspath_entry *entry,
>> const char *buf, size_t coun
>>
>>   	/* We'll use a local copy of buf */
>>   	count = min_t(size_t, count, sizeof(in)-1);
>> -	strncpy(in, buf, count);
>> -	in[count] = '\0';
>> +	strscpy(in, buf, sizeof(in));
>
> What is "count" now needed for? Looks like a write only variable at least in
> these hunks.

isn't count the return value?

Helge

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

end of thread, other threads:[~2022-12-27 21:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-26 10:40 [PATCH linux-next v2] parisc: use strscpy() to instead of strncpy() yang.yang29
2022-12-27  7:47 ` Rolf Eike Beer
2022-12-27 21:30   ` Helge Deller

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