Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ALSA: pcmtest: Replace deprecated strcpy with strscpy_pad in setup_patt_bufs

strcpy() has been deprecated [1] because it performs no bounds checking
on the destination buffer, which can lead to buffer overflows. Replace
it with the safer strscpy_pad(), and use kmalloc() instead of kzalloc()
because strscpy_pad() zero-pads the destination buffer and therefore
avoids writing to it twice.

Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strcpy [1]
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Link: https://patch.msgid.link/20251119135217.233084-1-thorsten.blum@linux.dev
Signed-off-by: Takashi Iwai <tiwai@suse.de>

authored by

Thorsten Blum and committed by
Takashi Iwai
ad5f82ab 18a48953

+2 -2
+2 -2
sound/drivers/pcmtest.c
··· 696 696 size_t i; 697 697 698 698 for (i = 0; i < ARRAY_SIZE(patt_bufs); i++) { 699 - patt_bufs[i].buf = kzalloc(MAX_PATTERN_LEN, GFP_KERNEL); 699 + patt_bufs[i].buf = kmalloc(MAX_PATTERN_LEN, GFP_KERNEL); 700 700 if (!patt_bufs[i].buf) 701 701 break; 702 - strcpy(patt_bufs[i].buf, DEFAULT_PATTERN); 702 + strscpy_pad(patt_bufs[i].buf, DEFAULT_PATTERN, MAX_PATTERN_LEN); 703 703 patt_bufs[i].len = DEFAULT_PATTERN_LEN; 704 704 } 705 705