Skip to contentSkip to conversation

accessibility: speakup: refactor deprecated strcpy

PATCH In review Ajith P V 2 participants 2 messages Aug 7 Speakup console speech driver

lore
Share & tools
lore

Ajith P V

author
#0 lore raw

PATCH 1/1 accessibility: speakup: refactor deprecated strcpy

strcpy() is deprecated, use strscpy() instead.

As strcpy() performs no bounds checking on the destination buffer. This could result in buffer overflow. The safe replacement is strscpy() [1][2].

---
 drivers/accessibility/speakup/varhandlers.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/accessibility/speakup/varhandlers.c +3 -2
index 462f8d879053..c6d3b4cc1af8 100644
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 #include <linux/ctype.h>
+#include <linux/string.h>
 #include "spk_types.h"
 #include "spk_priv.h"
 #include "speakup.h"
@@ -265,10 +266,10 @@ int spk_set_string_var(const char *page, struct st_var_header *var, int len)
 		if (!var->p_val)
 			var->p_val = var_data->u.s.default_val;
 		if (var->p_val != var_data->u.s.default_val)
-			strcpy((char *)var->p_val, var_data->u.s.default_val);
+			strscpy((char *)var->p_val, var_data->u.s.default_val, MAXVARLEN + 1);
 		return -ERESTART;
 	} else if (var->p_val) {
-		strcpy((char *)var->p_val, page);
+		strscpy((char *)var->p_val, page, MAXVARLEN + 1);
 	} else {
 		return -E2BIG;
 	}
Signature · 1 line
2.43.0
maintainer Reviewed-by on v1 1/1
#1 lore raw

Ajith P V, le ven. 07 août 2026 11:10:58 +0000, a ecrit:

Quoted 9 lines

strcpy() is deprecated, use strscpy() instead.

As strcpy() performs no bounds checking on the destination buffer. This could result in buffer overflow. The safe replacement is strscpy() [1][2].

Quoted 30 lines
---
 drivers/accessibility/speakup/varhandlers.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/accessibility/speakup/varhandlers.c +3 -2
index 462f8d879053..c6d3b4cc1af8 100644
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 #include <linux/ctype.h>
+#include <linux/string.h>
 #include "spk_types.h"
 #include "spk_priv.h"
 #include "speakup.h"
@@ -265,10 +266,10 @@ int spk_set_string_var(const char *page, struct st_var_header *var, int len)
 		if (!var->p_val)
 			var->p_val = var_data->u.s.default_val;
 		if (var->p_val != var_data->u.s.default_val)
-			strcpy((char *)var->p_val, var_data->u.s.default_val);
+			strscpy((char *)var->p_val, var_data->u.s.default_val, MAXVARLEN + 1);
 		return -ERESTART;
 	} else if (var->p_val) {
-		strcpy((char *)var->p_val, page);
+		strscpy((char *)var->p_val, page, MAXVARLEN + 1);
 	} else {
 		return -E2BIG;
 	}
Signature · 1 line
2.43.0