[alsa-devel] [PATCH (alsa-lib)] pcm_hw: Fix buffer overflow in chmap
We can't calculate memory storage in bytes, when we're supposed to store ints in it!
Signed-off-by: David Henningsson david.henningsson@canonical.com --- src/pcm/pcm_hw.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/pcm/pcm_hw.c b/src/pcm/pcm_hw.c index 196393d..9ff83a9 100644 --- a/src/pcm/pcm_hw.c +++ b/src/pcm/pcm_hw.c @@ -1187,7 +1187,7 @@ static snd_pcm_chmap_t *snd_pcm_hw_get_chmap(snd_pcm_t *pcm) snd_pcm_state_name(FAST_PCM_STATE(hw))); return NULL; } - map = malloc(pcm->channels + 1); + map = malloc(pcm->channels * sizeof(map->pos[0]) + sizeof(*map)); if (!map) return NULL; map->channels = pcm->channels;
When explicitly specifying channel maps, we need to use that when loading wave files so the correct file is played back.
Signed-off-by: David Henningsson david.henningsson@canonical.com --- speaker-test/speaker-test.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/speaker-test/speaker-test.c b/speaker-test/speaker-test.c index a41b5bd..a04043a 100644 --- a/speaker-test/speaker-test.c +++ b/speaker-test/speaker-test.c @@ -771,8 +771,16 @@ static int setup_wav_file(int chn)
if (given_test_wav_file) return check_wav_file(chn, given_test_wav_file); - else - return check_wav_file(chn, wavs[chn]); + +#ifdef CONFIG_SUPPORT_CHMAP + if (channel_map_set && chn < channel_map->channels) { + int channel = channel_map->pos[chn] - SND_CHMAP_FL; + if (channel >= 0 && channel < MAX_CHANNELS) + return check_wav_file(chn, wavs[channel]); + } +#endif + + return check_wav_file(chn, wavs[chn]); }
static int read_wav(uint16_t *buf, int channel, int offset, int bufsize) @@ -1179,7 +1187,7 @@ int main(int argc, char *argv[]) {
if (test_type == TEST_WAV) { for (chn = 0; chn < channels; chn++) { - if (setup_wav_file(chn) < 0) + if (setup_wav_file(get_speaker_channel(chn)) < 0) prg_exit(EXIT_FAILURE); } }
participants (1)
-
David Henningsson