]> www.infradead.org Git - users/hch/configfs.git/commitdiff
ALSA: pcm: Fix id copying in snd_pcm_set_sync_per_card()
authorJaroslav Kysela <perex@perex.cz>
Fri, 5 Jul 2024 07:58:28 +0000 (09:58 +0200)
committerTakashi Iwai <tiwai@suse.de>
Fri, 5 Jul 2024 08:02:07 +0000 (10:02 +0200)
Avoid to use strncpy and do proper length limiting (12 bytes)
to avoid out of array access.

Fixes: d712c58c55d9 ("ALSA: pcm: optimize and clarify stream synchronization ID API")
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202407050501.o5Z3bibi-lkp@intel.com/
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
Link: https://patch.msgid.link/20240705075828.19746-1-perex@perex.cz
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/core/pcm_lib.c

index 66683656fb13e224eee9512b83c975ca2261c21c..6e7905749c4a3b60be131622309a9d308a5aa499 100644 (file)
@@ -543,8 +543,8 @@ void snd_pcm_set_sync_per_card(struct snd_pcm_substream *substream,
                               const unsigned char *id, unsigned int len)
 {
        *(__u32 *)params->sync = cpu_to_le32(substream->pcm->card->number);
-       len = max(12, len);
-       strncpy(params->sync + 4, id, len);
+       len = min(12, len);
+       memcpy(params->sync + 4, id, len);
        memset(params->sync + 4 + len, 0, 12 - len);
 }
 EXPORT_SYMBOL_GPL(snd_pcm_set_sync_per_card);