Re: [PATCH] ALSA: mixer_oss: Replace deprecated strcpy() with strscpy()
From: Thorsten Blum
Date: Thu Jun 19 2025 - 08:50:47 EST
On 19. Jun 2025, at 00:49, Al Viro wrote:
> On Thu, Jun 19, 2025 at 12:36:29AM +0200, Thorsten Blum wrote:
>> strcpy() is deprecated; use strscpy() instead.
>>
>> No functional changes intended.
>
> Have you actually read the damn thing? Seriously, look at the uses
> of 'str' downstream. The only thing it is ever passed to is strcmp().
>
> In other words, why do we need to copy it anywhere? What's wrong with
> having char *str instead of that array and replacing strcpy() with
> plain and simple pointer assignment?
I read it, but didn't question whether copying was actually necessary.
However, it looks like 'ptr->name' can originate from userland (via proc
file - see the function comment), which could make using 'char *str'
directly unsafe, unless I'm missing something.
Something like this would skip one copy while keeping it safe:
char tmp_str[64];
char *str;
strscpy(tmp_str, ptr->name);
if (!strcmp(tmp_str, "Master"))
str = "Mix";
else if (!strcmp(tmp_str, "Master Mono"))
str = "Mix Mono";
else
str = tmp_str;
Thanks,
Thorsten