Skip to contentSkip to conversation

ALSA: pcmtest: Replace deprecated strcpy with strscpy_pad in setup_patt_bufs

PATCH Applied Thorsten Blum 2 participants 2 messages Nov 19, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---
 sound/drivers/pcmtest.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
sound/drivers/pcmtest.c +2 -2
index 19b3f306c564..b8474631f0b5 100644
@@ -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;
 	}
 
Signature · 1 line
2.51.1
Applied
#1 lore raw
Quoted 9 lines · Thorsten Blum

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.

Applied to for-next branch now. Thanks.

Takashi