Skip to content

Commit 8704109

Browse files
azeemshaikh38kees
authored andcommitted
sh: Replace all non-returning strlcpy with strscpy
strlcpy() reads the entire source buffer first. This read may exceed the destination size limit. This is both inefficient and can lead to linear read overflows if a source string is not NUL-terminated [1]. In an effort to remove strlcpy() completely [2], replace strlcpy() here with strscpy(). No return values were used, so direct replacement is safe. [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy [2] KSPP#89 Signed-off-by: Azeem Shaikh <[email protected]> Acked-by: John Paul Adrian Glaubitz <[email protected]> Tested-by: John Paul Adrian Glaubitz <[email protected]> Signed-off-by: Kees Cook <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent fdd932e commit 8704109

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

arch/sh/drivers/dma/dma-api.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ int request_dma(unsigned int chan, const char *dev_id)
198198
if (atomic_xchg(&channel->busy, 1))
199199
return -EBUSY;
200200

201-
strlcpy(channel->dev_id, dev_id, sizeof(channel->dev_id));
201+
strscpy(channel->dev_id, dev_id, sizeof(channel->dev_id));
202202

203203
if (info->ops->request) {
204204
result = info->ops->request(channel);

arch/sh/kernel/setup.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,9 @@ void __init setup_arch(char **cmdline_p)
304304
bss_resource.end = virt_to_phys(__bss_stop)-1;
305305

306306
#ifdef CONFIG_CMDLINE_OVERWRITE
307-
strlcpy(command_line, CONFIG_CMDLINE, sizeof(command_line));
307+
strscpy(command_line, CONFIG_CMDLINE, sizeof(command_line));
308308
#else
309-
strlcpy(command_line, COMMAND_LINE, sizeof(command_line));
309+
strscpy(command_line, COMMAND_LINE, sizeof(command_line));
310310
#ifdef CONFIG_CMDLINE_EXTEND
311311
strlcat(command_line, " ", sizeof(command_line));
312312
strlcat(command_line, CONFIG_CMDLINE, sizeof(command_line));

0 commit comments

Comments
 (0)