Skip to contentSkip to conversation

ALSA: pcm: Fix id copying in snd_pcm_set_sync_per_card()

PATCH Applied Jaroslav Kysela 2 participants 2 messages Jul 5, 2024 Sound

lore
Share & tools
lore

Jaroslav Kysela

author maintainer
#0 lore raw

PATCH 1/1 ALSA: pcm: Fix id copying in snd_pcm_set_sync_per_card()

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

---
 sound/core/pcm_lib.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
sound/core/pcm_lib.c +2 -2
index c105a7597ff6..40ca8c2b6303 100644
@@ -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);
Signature · 1 line
2.45.2