Skip to contentSkip to conversation

ALSA: control: Trim whitespace from sysfs input

PATCH Superseded Sreeraj S Kurup 3 participants 6 messages Nov 6 – Nov 7 Sound

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ALSA: control: Trim whitespace from sysfs input

The attach and detach sysfs interfaces receive input from userspace.

When userspace writes a value using echo, the input normally ends with a newline character.

The parser does not remove this newline in all input formats. For example, a bare numeric ID can be treated as a control name, and an unquoted name= field can include the newline.

Trim leading and trailing whitespace before parsing the input.

This keeps spaces inside mixer control names unchanged.

---
 sound/core/control_led.c | 5 +++++
 1 file changed, 5 insertions(+)
sound/core/control_led.c +5 -0
index 501387287ae6..a640e7835ce2 100644
@@ -518,6 +518,11 @@ static ssize_t set_led_id(struct snd_ctl_led_card *led_card, const char *buf, si
 
 	if (strscpy(buf2, buf, sizeof(buf2)) < 0)
 		return -E2BIG;
+
+	s = strim(buf2);
+	if (s != buf2)
+		memmove(buf2, s, strlen(s) + 1);
+
 	memset(&id, 0, sizeof(id));
 	id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
 	s = buf2;
Signature · 1 line
2.55.0
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] ALSA: control: missing Fixes trailer for set_led_id() whitespace fix --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] ALSA: control: missing Fixes trailer for set_led_id() whitespace fix
--

commit fba9994b6098b77ca57c53a57ff6876210ceae6a
Author: Sreeraj S Kurup <[email protected]>

Quoted 12 lines

ALSA: control: Trim whitespace from sysfs input

The attach and detach sysfs interfaces receive input from userspace.

When userspace writes a value using echo, the input normally ends with a newline character.

The parser does not remove this newline in all input formats. For example, a bare numeric ID can be treated as a control name, and an unquoted name= field can include the newline.

Quoted 5 lines

Trim leading and trailing whitespace before parsing the input.

This keeps spaces inside mixer control names unchanged.

[Severity: Low]
Since this fixes newline handling in set_led_id(), should it include:

Fixes a135dfb5de15 ("ALSA: led control - add sysfs kcontrol LED marking layer")
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw

PATCH v2 1/1 ALSA: control: Trim whitespace from sysfs input

In reply to Sreeraj S Kurup

The attach and detach sysfs interfaces receive input from userspace.

When userspace writes a value using echo, the input normally ends with a newline character.

The parser does not remove this newline in all input formats. For example, a bare numeric ID can be treated as a control name, and an unquoted name= field can include the newline.

Trim leading and trailing whitespace before parsing the input.

This keeps spaces inside mixer control names unchanged.

Fixes a135dfb5de15 ("ALSA: led control - add sysfs kcontrol LED marking layer")

---
v2:
- Add the Fixes trailer.

 sound/core/control_led.c | 5 +++++
 1 file changed, 5 insertions(+)
sound/core/control_led.c +5 -0
index 501387287ae6..a640e7835ce2 100644
@@ -518,6 +518,11 @@ static ssize_t set_led_id(struct snd_ctl_led_card *led_card, const char *buf, si
 
 	if (strscpy(buf2, buf, sizeof(buf2)) < 0)
 		return -E2BIG;
+
+	s = strim(buf2);
+	if (s != buf2)
+		memmove(buf2, s, strlen(s) + 1);
+
 	memset(&id, 0, sizeof(id));
 	id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
 	s = buf2;
Signature · 1 line
2.55.0
Applied
#3 lore raw
Quoted 11 lines · Sreeraj S Kurup

The attach and detach sysfs interfaces receive input from userspace.

When userspace writes a value using echo, the input normally ends with a newline character.

The parser does not remove this newline in all input formats. For example, a bare numeric ID can be treated as a control name, and an unquoted name= field can include the newline.

Quoted 6 lines

Trim leading and trailing whitespace before parsing the input.

This keeps spaces inside mixer control names unchanged.

Fixes a135dfb5de15 ("ALSA: led control - add sysfs kcontrol LED marking layer")

Applied to for-next branch. Thanks.

Takashi