[PATCH linux-next v2] accessibility: speakup: use strscpy() to instead of strncpy()

From: yang.yang29
Date: Mon Dec 05 2022 - 06:28:58 EST


From: Xu Panda <xu.panda@xxxxxxxxxx>

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@xxxxxxxxxx>
Signed-off-by: Yang Yang <yang.yang29@xxxxxxx>
Signed-off-by: Samuel Thibault <samuel.thibault@xxxxxxxxxxxx>
---
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