1 |
From 70051cffb31b5ee09096351c3b41fcae6f89de31 Mon Sep 17 00:00:00 2001 |
2 |
From: Jaroslav Kysela <perex@perex.cz> |
3 |
Date: Mon, 9 Jan 2023 16:12:49 +0100 |
4 |
Subject: ALSA: control-led: use strscpy in set_led_id() |
5 |
|
6 |
From: Jaroslav Kysela <perex@perex.cz> |
7 |
|
8 |
commit 70051cffb31b5ee09096351c3b41fcae6f89de31 upstream. |
9 |
|
10 |
The use of strncpy() in the set_led_id() was incorrect. |
11 |
The len variable should use 'min(sizeof(buf2) - 1, count)' |
12 |
expression. |
13 |
|
14 |
Use strscpy() function to simplify things and handle the error gracefully. |
15 |
|
16 |
Fixes: a135dfb5de15 ("ALSA: led control - add sysfs kcontrol LED marking layer") |
17 |
Reported-by: yang.yang29@zte.com.cn |
18 |
Link: https://lore.kernel.org/alsa-devel/202301091945513559977@zte.com.cn/ |
19 |
Cc: <stable@vger.kernel.org> |
20 |
Signed-off-by: Jaroslav Kysela <perex@perex.cz> |
21 |
Signed-off-by: Takashi Iwai <tiwai@suse.de> |
22 |
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> |
23 |
--- |
24 |
sound/core/control_led.c | 5 ++--- |
25 |
1 file changed, 2 insertions(+), 3 deletions(-) |
26 |
|
27 |
--- a/sound/core/control_led.c |
28 |
+++ b/sound/core/control_led.c |
29 |
@@ -530,12 +530,11 @@ static ssize_t set_led_id(struct snd_ctl |
30 |
bool attach) |
31 |
{ |
32 |
char buf2[256], *s, *os; |
33 |
- size_t len = max(sizeof(s) - 1, count); |
34 |
struct snd_ctl_elem_id id; |
35 |
int err; |
36 |
|
37 |
- strncpy(buf2, buf, len); |
38 |
- buf2[len] = '\0'; |
39 |
+ if (strscpy(buf2, buf, sizeof(buf2)) < 0) |
40 |
+ return -E2BIG; |
41 |
memset(&id, 0, sizeof(id)); |
42 |
id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; |
43 |
s = buf2; |