ALSA: usb-audio: Stop parsing channels bits when all channels are found.
authorJohan Carlsson <johan.carlsson@teenage.engineering>
Wed, 13 Mar 2024 08:15:09 +0000 (09:15 +0100)
committerTakashi Iwai <tiwai@suse.de>
Wed, 13 Mar 2024 13:29:22 +0000 (14:29 +0100)
If a usb audio device sets more bits than the amount of channels
it could write outside of the map array.

Signed-off-by: Johan Carlsson <johan.carlsson@teenage.engineering>
Fixes: 04324ccc75f9 ("ALSA: usb-audio: add channel map support")
Message-ID: <20240313081509.9801-1-johan.carlsson@teenage.engineering>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/usb/stream.c

index 3d4add94e367d63d1329f22ddb78af4264685580..d5409f3879455961182713d24327836219e73457 100644 (file)
@@ -300,9 +300,12 @@ static struct snd_pcm_chmap_elem *convert_chmap(int channels, unsigned int bits,
        c = 0;
 
        if (bits) {
-               for (; bits && *maps; maps++, bits >>= 1)
+               for (; bits && *maps; maps++, bits >>= 1) {
                        if (bits & 1)
                                chmap->map[c++] = *maps;
+                       if (c == chmap->channels)
+                               break;
+               }
        } else {
                /* If we're missing wChannelConfig, then guess something
                    to make sure the channel map is not skipped entirely */