[PATCH] kdb: Replace deprecated strcpy() with strscpy()

Thorsten Blum posted 1 patch 2 months, 2 weeks ago
There is a newer version of this series
kernel/debug/kdb/kdb_support.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
[PATCH] kdb: Replace deprecated strcpy() with strscpy()
Posted by Thorsten Blum 2 months, 2 weeks ago
strcpy() is deprecated; use strscpy() instead.

Link: https://github.com/KSPP/linux/issues/88
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
 kernel/debug/kdb/kdb_support.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/kernel/debug/kdb/kdb_support.c b/kernel/debug/kdb/kdb_support.c
index 05b137e7dcb9..158430a890b6 100644
--- a/kernel/debug/kdb/kdb_support.c
+++ b/kernel/debug/kdb/kdb_support.c
@@ -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;
 }
 
 /*
-- 
2.50.1
Re: [PATCH] kdb: Replace deprecated strcpy() with strscpy()
Posted by Doug Anderson 2 months, 2 weeks ago
Hi,

On Fri, Jul 18, 2025 at 2:40 PM Thorsten Blum <thorsten.blum@linux.dev> wrote:
>
> strcpy() is deprecated; use strscpy() instead.
>
> Link: https://github.com/KSPP/linux/issues/88
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> ---
>  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.

Reviewed-by: Douglas Anderson <dianders@chromium.org>
Re: [PATCH] kdb: Replace deprecated strcpy() with strscpy()
Posted by Thorsten Blum 1 month, 2 weeks ago
Hi Doug,

On 19. Jul 2025, at 00:48, Doug Anderson wrote:
> On Fri, Jul 18, 2025 at 2:40 PM Thorsten Blum wrote:
>> 
>> strcpy() is deprecated; use strscpy() instead.
>> 
>> Link: https://github.com/KSPP/linux/issues/88
>> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
>> ---
>> 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.
> 
> Reviewed-by: Douglas Anderson <dianders@chromium.org>

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
Re: [PATCH] kdb: Replace deprecated strcpy() with strscpy()
Posted by Doug Anderson 1 month, 2 weeks ago
Hi,

On Mon, Aug 18, 2025 at 4:03 AM Thorsten Blum <thorsten.blum@linux.dev> wrote:
>
> Hi Doug,
>
> On 19. Jul 2025, at 00:48, Doug Anderson wrote:
> > On Fri, Jul 18, 2025 at 2:40 PM Thorsten Blum wrote:
> >>
> >> strcpy() is deprecated; use strscpy() instead.
> >>
> >> Link: https://github.com/KSPP/linux/issues/88
> >> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> >> ---
> >> 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.
> >
> > Reviewed-by: Douglas Anderson <dianders@chromium.org>
>
> 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?

Sure.