public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH linux-next v2] accessibility: speakup: use strscpy() to instead of strncpy()
@ 2022-12-05 11:28 yang.yang29
  2022-12-05 12:37 ` Samuel Thibault
  0 siblings, 1 reply; 2+ messages in thread
From: yang.yang29 @ 2022-12-05 11:28 UTC (permalink / raw)
  To: w.d.hubbs
  Cc: chris, kirk, samuel.thibault, mushi.shar, speakup, 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.
---
change for v2
 - fix the mistake of eating one character when len > 250,
thanks to Samuel Thibault.
---

Signed-off-by: Xu Panda <xu.panda@zte.com.cn>
Signed-off-by: Yang Yang <yang.yang29@zte.com>
Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
---
 drivers/accessibility/speakup/kobjects.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/accessibility/speakup/kobjects.c b/drivers/accessibility/speakup/kobjects.c
index a7522d409802..c1ef48280f3c 100644
--- a/drivers/accessibility/speakup/kobjects.c
+++ b/drivers/accessibility/speakup/kobjects.c
@@ -426,8 +426,7 @@ static ssize_t synth_direct_store(struct kobject *kobj,
 	spin_lock_irqsave(&speakup_info.spinlock, flags);
 	while (len > 0) {
 		bytes = min_t(size_t, len, 250);
-		strncpy(tmp, ptr, bytes);
-		tmp[bytes] = '\0';
+		strscpy(tmp, ptr, bytes + 1);
 		string_unescape_any_inplace(tmp);
 		synth_printf("%s", tmp);
 		ptr += bytes;
-- 
2.15.2

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

* Re: [PATCH linux-next v2] accessibility: speakup: use strscpy() to instead of strncpy()
  2022-12-05 11:28 [PATCH linux-next v2] accessibility: speakup: use strscpy() to instead of strncpy() yang.yang29
@ 2022-12-05 12:37 ` Samuel Thibault
  0 siblings, 0 replies; 2+ messages in thread
From: Samuel Thibault @ 2022-12-05 12:37 UTC (permalink / raw)
  To: yang.yang29
  Cc: w.d.hubbs, chris, kirk, mushi.shar, speakup, linux-kernel,
	xu.panda

yang.yang29@zte.com.cn, le lun. 05 déc. 2022 19:28:46 +0800, a ecrit:
> 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.
> ---
> change for v2
>  - fix the mistake of eating one character when len > 250,
> thanks to Samuel Thibault.
> ---
> 
> Signed-off-by: Xu Panda <xu.panda@zte.com.cn>
> Signed-off-by: Yang Yang <yang.yang29@zte.com>
> Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

It's not really a signed-off from my side, I just did a review :)

but with that version,

Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

> ---
>  drivers/accessibility/speakup/kobjects.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/accessibility/speakup/kobjects.c b/drivers/accessibility/speakup/kobjects.c
> index a7522d409802..c1ef48280f3c 100644
> --- a/drivers/accessibility/speakup/kobjects.c
> +++ b/drivers/accessibility/speakup/kobjects.c
> @@ -426,8 +426,7 @@ static ssize_t synth_direct_store(struct kobject *kobj,
>  	spin_lock_irqsave(&speakup_info.spinlock, flags);
>  	while (len > 0) {
>  		bytes = min_t(size_t, len, 250);
> -		strncpy(tmp, ptr, bytes);
> -		tmp[bytes] = '\0';
> +		strscpy(tmp, ptr, bytes + 1);
>  		string_unescape_any_inplace(tmp);
>  		synth_printf("%s", tmp);
>  		ptr += bytes;
> -- 
> 2.15.2
> 

-- 
Samuel
---
Pour une évaluation indépendante, transparente et rigoureuse !
Je soutiens la Commission d'Évaluation de l'Inria.

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

end of thread, other threads:[~2022-12-05 12:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-05 11:28 [PATCH linux-next v2] accessibility: speakup: use strscpy() to instead of strncpy() yang.yang29
2022-12-05 12:37 ` Samuel Thibault

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