[PATCH] mips: math-emu: replace deprecated strcpy() in me-debugfs

Osama Abdelkader posted 1 patch 1 month ago
There is a newer version of this series
arch/mips/math-emu/me-debugfs.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] mips: math-emu: replace deprecated strcpy() in me-debugfs
Posted by Osama Abdelkader 1 month ago
use strscpy() instead of deprecated strcpy().

Signed-off-by: Osama Abdelkader <osama.abdelkader@gmail.com>
---
 arch/mips/math-emu/me-debugfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/mips/math-emu/me-debugfs.c b/arch/mips/math-emu/me-debugfs.c
index d5ad76b2bb67..94667cbe18e7 100644
--- a/arch/mips/math-emu/me-debugfs.c
+++ b/arch/mips/math-emu/me-debugfs.c
@@ -41,7 +41,7 @@ static void adjust_instruction_counter_name(char *out_name, char *in_name)
 {
 	int i = 0;
 
-	strcpy(out_name, in_name);
+	strscpy(out_name, in_name, sizeof(out_name));
 	while (in_name[i] != '\0') {
 		if (out_name[i] == '_')
 			out_name[i] = '.';
-- 
2.43.0
Re: [PATCH] mips: math-emu: replace deprecated strcpy() in me-debugfs
Posted by Thomas Bogendoerfer 1 month ago
On Mon, Sep 01, 2025 at 03:39:19PM +0200, Osama Abdelkader wrote:
> use strscpy() instead of deprecated strcpy().
> 
> Signed-off-by: Osama Abdelkader <osama.abdelkader@gmail.com>
> ---
>  arch/mips/math-emu/me-debugfs.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/mips/math-emu/me-debugfs.c b/arch/mips/math-emu/me-debugfs.c
> index d5ad76b2bb67..94667cbe18e7 100644
> --- a/arch/mips/math-emu/me-debugfs.c
> +++ b/arch/mips/math-emu/me-debugfs.c
> @@ -41,7 +41,7 @@ static void adjust_instruction_counter_name(char *out_name, char *in_name)
>  {
>  	int i = 0;
>  
> -	strcpy(out_name, in_name);
> +	strscpy(out_name, in_name, sizeof(out_name));

this is wrong. sizeof(out_name) is the size of the pointer, but not the
size of the storage behind it. To be able to use strscpy() here you
need to pass in the size of the given buffer and use that.

Thomas.

-- 
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea.                                                [ RFC1925, 2.3 ]
Re: [PATCH] mips: math-emu: replace deprecated strcpy() in me-debugfs
Posted by Osama Abdelkader 1 month ago
On Tue, Sep 02, 2025 at 01:55:47PM +0200, Thomas Bogendoerfer wrote:
> On Mon, Sep 01, 2025 at 03:39:19PM +0200, Osama Abdelkader wrote:
> > use strscpy() instead of deprecated strcpy().
> > 
> > Signed-off-by: Osama Abdelkader <osama.abdelkader@gmail.com>
> > ---
> >  arch/mips/math-emu/me-debugfs.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/arch/mips/math-emu/me-debugfs.c b/arch/mips/math-emu/me-debugfs.c
> > index d5ad76b2bb67..94667cbe18e7 100644
> > --- a/arch/mips/math-emu/me-debugfs.c
> > +++ b/arch/mips/math-emu/me-debugfs.c
> > @@ -41,7 +41,7 @@ static void adjust_instruction_counter_name(char *out_name, char *in_name)
> >  {
> >  	int i = 0;
> >  
> > -	strcpy(out_name, in_name);
> > +	strscpy(out_name, in_name, sizeof(out_name));
> 
> this is wrong. sizeof(out_name) is the size of the pointer, but not the
> size of the storage behind it. To be able to use strscpy() here you
> need to pass in the size of the given buffer and use that.
> 
> Thomas.
> 

Thanks Thomas, I just sent v2.

Regards,
Osama

> -- 
> Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
> good idea.                                                [ RFC1925, 2.3 ]