accessibility: speakup: use strscpy() to instead of strncpy()
PATCH v2 1/1 accessibility: speakup: use strscpy() to instead of strncpy()
From: Xu Panda <[email protected]>
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 <[email protected]>
Signed-off-by Yang Yang <[email protected]>
Signed-off-by Samuel Thibault <[email protected]>
--- drivers/accessibility/speakup/kobjects.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/accessibility/speakup/kobjects.c +1 -2
@@ -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;
Signature · 1 line
2.15.2
[email protected], le lun. 05 déc. 2022 19:28:46 +0800, a ecrit:
Quoted 10 lines
From: Xu Panda <[email protected]>
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.
---
Quoted 3 lines
Signed-off-by Xu Panda <[email protected]>Signed-off-by Yang Yang <[email protected]>Signed-off-by Samuel Thibault <[email protected]>
It's not really a signed-off from my side, I just did a review :)
but with that version,
Reviewed-by Samuel Thibault <[email protected]>
Quoted 21 lines
--- drivers/accessibility/speakup/kobjects.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/accessibility/speakup/kobjects.c +1
-2@@ -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;Signature · 1 line
2.15.2
Signature · 4 lines
Samuel --- Pour une évaluation indépendante, transparente et rigoureuse ! Je soutiens la Commission d'Évaluation de l'Inria.