Skip to content

Commit 70051cf

Browse files
perexgtiwai
authored andcommitted
ALSA: control-led: use strscpy in set_led_id()
The use of strncpy() in the set_led_id() was incorrect. The len variable should use 'min(sizeof(buf2) - 1, count)' expression. Use strscpy() function to simplify things and handle the error gracefully. Fixes: a135dfb ("ALSA: led control - add sysfs kcontrol LED marking layer") Reported-by: [email protected] Link: https://lore.kernel.org/alsa-devel/[email protected]/ Cc: <[email protected]> Signed-off-by: Jaroslav Kysela <[email protected]> Signed-off-by: Takashi Iwai <[email protected]>
1 parent 291e9da commit 70051cf

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

sound/core/control_led.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -530,12 +530,11 @@ static ssize_t set_led_id(struct snd_ctl_led_card *led_card, const char *buf, si
530530
bool attach)
531531
{
532532
char buf2[256], *s, *os;
533-
size_t len = max(sizeof(s) - 1, count);
534533
struct snd_ctl_elem_id id;
535534
int err;
536535

537-
strncpy(buf2, buf, len);
538-
buf2[len] = '\0';
536+
if (strscpy(buf2, buf, sizeof(buf2)) < 0)
537+
return -E2BIG;
539538
memset(&id, 0, sizeof(id));
540539
id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
541540
s = buf2;

0 commit comments

Comments
 (0)