From: Harsh Raj Singhania Date: Wed, 30 Sep 2026 18:58:53 +0000 (+0530) Subject: pcm: replace multi plugin binding asserts with -EINVAL checks X-Git-Url: https://git.alsa-project.org/?a=commitdiff_plain;h=81c4a89eb445f8e991ca80ab55b5649530c0aacd;p=alsa-lib.git pcm: replace multi plugin binding asserts with -EINVAL checks 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 Signed-off-by: Takashi Iwai --- diff --git a/src/pcm/pcm_multi.c b/src/pcm/pcm_multi.c index 121c4c20..c7c67e73 100644 --- a/src/pcm/pcm_multi.c +++ b/src/pcm/pcm_multi.c @@ -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)