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>
}
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)