Skip to contentSkip to conversation

kdb: Replace deprecated strcpy() with strscpy()

PATCH In review Thorsten Blum 2 participants 4 messages Jul 18, 2025 – Aug 18, 2025 KGDB / KDB /debug_core

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kdb: Replace deprecated strcpy() with strscpy()

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

---
 kernel/debug/kdb/kdb_support.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/debug/kdb/kdb_support.c +3 -1
index 05b137e7dcb9..158430a890b6 100644
@@ -23,6 +23,7 @@
 #include <linux/uaccess.h>
 #include <linux/kdb.h>
 #include <linux/slab.h>
+#include <linux/string.h>
 #include <linux/ctype.h>
 #include "kdb_private.h"
 
@@ -250,7 +251,8 @@ char *kdb_strdup(const char *str, gfp_t type)
 	char *s = kmalloc(n, type);
 	if (!s)
 		return NULL;
-	return strcpy(s, str);
+	strscpy(s, str, n);
+	return s;
 }
 
 /*
Signature · 1 line
2.50.1
reviewer Reviewed-by on v1 1/1
#1 lore raw

Hi,

Quoted 8 lines · Thorsten Blum

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

---
 kernel/debug/kdb/kdb_support.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

nit: Since this only covers things in the file kdb_support.c and not everything in kernel/debug/kdb, perhaps that should be in the subject line? Maybe "kdb: Replace deprecated strcpy() with strscpy() in kdb_strdup()"?

Other than that, this looks fine to me.

#2 lore raw

Hi Doug,

Quoted 10 lines · Doug Anderson
Quoted 8 lines · Thorsten Blum

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

---
kernel/debug/kdb/kdb_support.c | 4 +++-

1 file changed, 3 insertions(+), 1 deletion(-)
Quoted 8 lines

nit: Since this only covers things in the file kdb_support.c and not everything in kernel/debug/kdb, perhaps that should be in the subject line? Maybe "kdb: Replace deprecated strcpy() with strscpy() in kdb_strdup()"?

Other than that, this looks fine to me.

I'm preparing a patch series for Daniel with my kdb changes.

For this one here, I initially used:

	strscpy(s, str, n);
	return s;

to replace 'return strcpy(s, str);', but now prefer:

	memcpy(s, str, n);
	return s;

because we already know the string length 'n'.

Can I keep your Reviewed-by: tag when making this change and submitting it as part of a patch series?

Thanks,
Thorsten

reviewer
#3 lore raw

Hi,

Quoted 32 lines · Thorsten Blum

Hi Doug,

Quoted 10 lines · Doug Anderson
Quoted 8 lines · Thorsten Blum

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

---
kernel/debug/kdb/kdb_support.c | 4 +++-

1 file changed, 3 insertions(+), 1 deletion(-)
Quoted 8 lines

nit: Since this only covers things in the file kdb_support.c and not everything in kernel/debug/kdb, perhaps that should be in the subject line? Maybe "kdb: Replace deprecated strcpy() with strscpy() in kdb_strdup()"?

Other than that, this looks fine to me.

I'm preparing a patch series for Daniel with my kdb changes.

For this one here, I initially used:

        strscpy(s, str, n);
        return s;

to replace 'return strcpy(s, str);', but now prefer:

Quoted 7 lines
        memcpy(s, str, n);
        return s;

because we already know the string length 'n'.

Can I keep your Reviewed-by: tag when making this change and submitting it as part of a patch series?

Sure.