diff mbox series

ALSA: pcm: Fix id copying in snd_pcm_set_sync_per_card()

Message ID 20240705075828.19746-1-perex@perex.cz (mailing list archive)
State Accepted
Commit a892b700e63bcb3679ebed1a0c3160e7b9225138
Headers show
Series ALSA: pcm: Fix id copying in snd_pcm_set_sync_per_card() | expand

Commit Message

Jaroslav Kysela July 5, 2024, 7:58 a.m. UTC
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>
---
 sound/core/pcm_lib.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Takashi Iwai July 5, 2024, 8:03 a.m. UTC | #1
On Fri, 05 Jul 2024 09:58:28 +0200,
Jaroslav Kysela wrote:
> 
> 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>

Thanks, applied.


Takashi
diff mbox series

Patch

diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c
index c105a7597ff6..40ca8c2b6303 100644
--- a/sound/core/pcm_lib.c
+++ b/sound/core/pcm_lib.c
@@ -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);