]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ALSA: pcmtest: Replace deprecated strcpy with strscpy_pad in setup_patt_bufs
authorThorsten Blum <thorsten.blum@linux.dev>
Wed, 19 Nov 2025 13:52:17 +0000 (14:52 +0100)
committerTakashi Iwai <tiwai@suse.de>
Wed, 19 Nov 2025 16:16:49 +0000 (17:16 +0100)
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
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>
sound/drivers/pcmtest.c

index 19b3f306c5645660831a4be7c4856931f9f8bbbd..b8474631f0b57686d96e45ad94ae691ebbd50827 100644 (file)
@@ -696,10 +696,10 @@ static int setup_patt_bufs(void)
        size_t i;
 
        for (i = 0; i < ARRAY_SIZE(patt_bufs); i++) {
-               patt_bufs[i].buf = kzalloc(MAX_PATTERN_LEN, GFP_KERNEL);
+               patt_bufs[i].buf = kmalloc(MAX_PATTERN_LEN, GFP_KERNEL);
                if (!patt_bufs[i].buf)
                        break;
-               strcpy(patt_bufs[i].buf, DEFAULT_PATTERN);
+               strscpy_pad(patt_bufs[i].buf, DEFAULT_PATTERN, MAX_PATTERN_LEN);
                patt_bufs[i].len = DEFAULT_PATTERN_LEN;
        }