Message ID | 20240313081509.9801-1-johan.carlsson@teenage.engineering (mailing list archive) |
---|---|
State | Accepted |
Commit | a39d51ff1f52cd0b6fe7d379ac93bd8b4237d1b7 |
Headers | show |
Series | [v2] ALSA: usb-audio: Stop parsing channels bits when all channels are found. | expand |
On Wed, 13 Mar 2024 09:15:09 +0100, Johan Carlsson wrote: > > 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> Applied now. Thanks. Takashi
diff --git a/sound/usb/stream.c b/sound/usb/stream.c index 3d4add94e367..d5409f387945 100644 --- a/sound/usb/stream.c +++ b/sound/usb/stream.c @@ -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 */
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> --- sound/usb/stream.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)