]> git.alsa-project.org Git - alsa-lib.git/commitdiff
pcm: multi: guard chmap handlers against unmapped channels
authorJaroslav Kysela <perex@perex.cz>
Mon, 30 Nov 2026 13:34:52 +0000 (14:34 +0100)
committerJaroslav Kysela <perex@perex.cz>
Mon, 30 Nov 2026 13:35:45 +0000 (14:35 +0100)
snd_pcm_multi_query_chmaps(), snd_pcm_multi_get_chmap() and
snd_pcm_multi_set_chmap() index multi->slaves[] / slave_maps[] with
bind->slave_idx without checking for the slave_idx < 0 sentinel used for
unmapped channels in sparse binding maps. For such channels this reads or
writes array index -1 (out of bounds).

Skip unmapped channels: report SND_CHMAP_UNKNOWN for the query/get paths
and leave them untouched on set. This matches the existing slave_idx < 0
handling elsewhere in the plugin (channel info, mmap commit, dump).

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
src/pcm/pcm_multi.c

index 9274a636453b7d53451e48a7a6fc4cc10d0e7304..005805386044e2c9720fe8d33bec9e3cf08f059a 100644 (file)
@@ -877,10 +877,16 @@ static snd_pcm_chmap_query_t **snd_pcm_multi_query_chmaps(snd_pcm_t *pcm)
 
        for (i = 0; i < multi->channels_count; i++) {
                snd_pcm_multi_channel_t *bind = &multi->channels[i];
-               unsigned int slave_channels =
-                       multi->slaves[bind->slave_idx].channels_count;
+               unsigned int slave_channels;
                snd_pcm_chmap_query_t **p;
 
+               if (bind->slave_idx < 0) {
+                       maps[0]->map.pos[i] = SND_CHMAP_UNKNOWN;
+                       continue;
+               }
+               slave_channels =
+                       multi->slaves[bind->slave_idx].channels_count;
+
                for (p = slave_maps[bind->slave_idx]; *p; p++) {
                        if ((*p)->map.channels == slave_channels) {
                                maps[0]->map.pos[i] =
@@ -927,6 +933,10 @@ static snd_pcm_chmap_t *snd_pcm_multi_get_chmap(snd_pcm_t *pcm)
        map->channels = multi->channels_count;
        for (i = 0; i < multi->channels_count; i++) {
                snd_pcm_multi_channel_t *bind = &multi->channels[i];
+               if (bind->slave_idx < 0) {
+                       map->pos[i] = SND_CHMAP_UNKNOWN;
+                       continue;
+               }
                map->pos[i] = slave_maps[bind->slave_idx]->pos[bind->slave_channel];
        }
        err = 0;
@@ -966,6 +976,8 @@ static int snd_pcm_multi_set_chmap(snd_pcm_t *pcm, const snd_pcm_chmap_t *map)
 
        for (i = 0; i < multi->channels_count; i++) {
                snd_pcm_multi_channel_t *bind = &multi->channels[i];
+               if (bind->slave_idx < 0)
+                       continue;
                slave_maps[bind->slave_idx]->pos[bind->slave_channel] =
                        map->pos[i];
        }