ALSA: control - off by one in store_mode()
authorDan Carpenter <dan.carpenter@oracle.com>
Fri, 2 Apr 2021 11:42:50 +0000 (14:42 +0300)
committerTakashi Iwai <tiwai@suse.de>
Tue, 6 Apr 2021 09:30:53 +0000 (11:30 +0200)
If count is 16 then this will put the NUL terminator one element beyond
the end of the array.

Fixes: cb17fe0045aa ("ALSA: control - add sysfs support to the LED trigger module")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: Jaroslav Kysela <perex@perex.cz>
Link: https://lore.kernel.org/r/YGcDOtrimR46vr0k@mwanda
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/core/control_led.c

index 788fd9e..d756a52 100644 (file)
@@ -391,7 +391,7 @@ static ssize_t store_mode(struct device *dev, struct device_attribute *attr,
 {
        struct snd_ctl_led *led = container_of(dev, struct snd_ctl_led, dev);
        char _buf[16];
-       size_t l = min(count, sizeof(_buf) - 1) + 1;
+       size_t l = min(count, sizeof(_buf) - 1);
        enum snd_ctl_led_mode mode;
 
        memcpy(_buf, buf, l);