Skip to contentSkip to conversation

ALSA: control led - improve the set_led_id() parser

PATCH Applied Jaroslav Kysela 2 participants 2 messages Mar 31, 2021 – Apr 1, 2021 Sound

lore
Share & tools
lore

Jaroslav Kysela

author maintainer
#0 lore raw

PATCH 1/1 ALSA: control led - improve the set_led_id() parser

It may be possible that the string pointer does not move when parsing. Add a code which detects this state and simply break the parser loop in this case.

---
 sound/core/control_led.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
sound/core/control_led.c +4 -1
index d4fb8b873f34..788fd9e275e0 100644
@@ -506,7 +506,7 @@ static char *parse_iface(char *s, unsigned int *val)
 static ssize_t set_led_id(struct snd_ctl_led_card *led_card, const char *buf, size_t count,
 			  bool attach)
 {
-	char buf2[256], *s;
+	char buf2[256], *s, *os;
 	size_t len = max(sizeof(s) - 1, count);
 	struct snd_ctl_elem_id id;
 	int err;
@@ -517,6 +517,7 @@ static ssize_t set_led_id(struct snd_ctl_led_card *led_card, const char *buf, si
 	id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
 	s = buf2;
 	while (*s) {
+		os = s;
 		if (!strncasecmp(s, "numid=", 6)) {
 			s = parse_uint(s + 6, &id.numid);
 		} else if (!strncasecmp(s, "iface=", 6)) {
@@ -546,6 +547,8 @@ static ssize_t set_led_id(struct snd_ctl_led_card *led_card, const char *buf, si
 		}
 		if (*s == ',')
 			s++;
+		if (s == os)
+			break;
 	}
 
 	err = snd_ctl_led_set_id(led_card->number, &id, led_card->led->group, attach);
Signature · 1 line
2.30.2
Applied
#1 lore raw
Quoted 6 lines · Jaroslav Kysela

It may be possible that the string pointer does not move when parsing. Add a code which detects this state and simply break the parser loop in this case.

Applied, thanks.

Takashi