All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] ALSA: control-led: use strscpy in set_led_id()
@ 2023-01-09 15:12 ` Jaroslav Kysela
  0 siblings, 0 replies; 4+ messages in thread
From: Jaroslav Kysela @ 2023-01-09 15:12 UTC (permalink / raw)
  To: ALSA development; +Cc: Takashi Iwai, yang.yang29, stable

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: a135dfb5de15 ("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>

v1..v2:
  - remove min() expression which strips the last char
v2..v3:
  - BugLink -> Link
  - add Fixes tag
---
 sound/core/control_led.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/sound/core/control_led.c b/sound/core/control_led.c
index f975cc85772b..3cadd40100f3 100644
--- a/sound/core/control_led.c
+++ b/sound/core/control_led.c
@@ -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;
-- 
2.39.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v3] ALSA: control-led: use strscpy in set_led_id()
@ 2023-01-09 15:12 ` Jaroslav Kysela
  0 siblings, 0 replies; 4+ messages in thread
From: Jaroslav Kysela @ 2023-01-09 15:12 UTC (permalink / raw)
  To: ALSA development; +Cc: Takashi Iwai, Jaroslav Kysela, yang.yang29, stable

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: a135dfb5de15 ("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>

v1..v2:
  - remove min() expression which strips the last char
v2..v3:
  - BugLink -> Link
  - add Fixes tag
---
 sound/core/control_led.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/sound/core/control_led.c b/sound/core/control_led.c
index f975cc85772b..3cadd40100f3 100644
--- a/sound/core/control_led.c
+++ b/sound/core/control_led.c
@@ -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;
-- 
2.39.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v3] ALSA: control-led: use strscpy in set_led_id()
  2023-01-09 15:12 ` Jaroslav Kysela
@ 2023-01-09 16:04   ` Takashi Iwai
  -1 siblings, 0 replies; 4+ messages in thread
From: Takashi Iwai @ 2023-01-09 16:04 UTC (permalink / raw)
  To: Jaroslav Kysela; +Cc: ALSA development, yang.yang29, stable

On Mon, 09 Jan 2023 16:12:49 +0100,
Jaroslav Kysela wrote:
> 
> 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: a135dfb5de15 ("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>
> 
> v1..v2:
>   - remove min() expression which strips the last char
> v2..v3:
>   - BugLink -> Link
>   - add Fixes tag

Thanks, applied.


Takashi

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v3] ALSA: control-led: use strscpy in set_led_id()
@ 2023-01-09 16:04   ` Takashi Iwai
  0 siblings, 0 replies; 4+ messages in thread
From: Takashi Iwai @ 2023-01-09 16:04 UTC (permalink / raw)
  To: Jaroslav Kysela; +Cc: yang.yang29, ALSA development, stable

On Mon, 09 Jan 2023 16:12:49 +0100,
Jaroslav Kysela wrote:
> 
> 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: a135dfb5de15 ("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>
> 
> v1..v2:
>   - remove min() expression which strips the last char
> v2..v3:
>   - BugLink -> Link
>   - add Fixes tag

Thanks, applied.


Takashi

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-01-09 16:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-09 15:12 [PATCH v3] ALSA: control-led: use strscpy in set_led_id() Jaroslav Kysela
2023-01-09 15:12 ` Jaroslav Kysela
2023-01-09 16:04 ` Takashi Iwai
2023-01-09 16:04   ` Takashi Iwai

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.