Skip to content

Commit

Permalink
ALSA: control-led: use strscpy in set_led_id()
Browse files Browse the repository at this point in the history
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: yang.yang29@zte.com.cn
Link: https://lore.kernel.org/alsa-devel/202301091945513559977@zte.com.cn/
Cc: <stable@vger.kernel.org>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
  • Loading branch information
Jaroslav Kysela authored and Takashi Iwai committed Jan 9, 2023
1 parent 291e9da commit 70051cf
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions sound/core/control_led.c
Original file line number Diff line number Diff line change
@@ -530,12 +530,11 @@ static ssize_t set_led_id(struct snd_ctl_led_card *led_card, const char *buf, si
bool attach)
{
char buf2[256], *s, *os;
size_t len = max(sizeof(s) - 1, count);
struct snd_ctl_elem_id id;
int err;

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

0 comments on commit 70051cf

Please sign in to comment.