]> git.alsa-project.org Git - alsa-lib.git/commitdiff
pcm: replace multi plugin binding asserts with -EINVAL checks
authorHarsh Raj Singhania <raj.harshraut@gmail.com>
Wed, 30 Sep 2026 18:58:53 +0000 (00:28 +0530)
committerTakashi Iwai <tiwai@suse.de>
Thu, 15 Oct 2026 13:46:44 +0000 (15:46 +0200)
Sparse binding maps leave sidxs[i] == -1 for gap indices. The previous
assert() calls caused SIGABRT in debug builds and OOB reads under NDEBUG.
Return -EINVAL with explicit bounds and sign checks instead.

[ fixed coding style -- tiwai ]

Closes: https://github.com/alsa-project/alsa-lib/pull/527
Signed-off-by: Harsh Raj Singhania <raj.harshraut@gmail.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
src/pcm/pcm_multi.c

index 121c4c2070a38ec41fa368d3eb2aa011d2d14633..c7c67e734946ad2490db65da185c8e9adba32db5 100644 (file)
@@ -1121,8 +1121,16 @@ int snd_pcm_multi_open(snd_pcm_t **pcmp, const char *name,
        }
        for (i = 0; i < channels_count; ++i) {
                snd_pcm_multi_channel_t *bind = &multi->channels[i];
-               assert(sidxs[i] < (int)slaves_count);
-               assert(schannels[i] < schannels_count[sidxs[i]]);
+               if (sidxs[i] < 0 || sidxs[i] >= (int)slaves_count) {
+                       SNDERR("multi: ch %d invalid slave idx %d",
+                              i, sidxs[i]);
+                       return -EINVAL;
+               }
+               if (schannels[i] >= schannels_count[sidxs[i]]) {
+                       SNDERR("multi: ch %d channel %d out of range",
+                              i, schannels[i]);
+                       return -EINVAL;
+               }
                bind->slave_idx = sidxs[i];
                bind->slave_channel = schannels[i];
                if (sidxs[i] < 0)