Skip to content

Commit

Permalink
i2c: sun6i-pw2i: Prefer strscpy over strlcpy
Browse files Browse the repository at this point in the history
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. The safe
replacement is strscpy().

This is a previous step in the path to remove the strlcpy() function
entirely from the kernel [1].

[1] https://github.com/KSPP/linux/issues/89

Signed-off-by: Len Baker <len.baker@gmx.com>
Signed-off-by: Wolfram Sang <wsa@kernel.org>
  • Loading branch information
Len Baker authored and Wolfram Sang committed Aug 17, 2021
1 parent e517992 commit e47a0ce
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion drivers/i2c/busses/i2c-sun6i-p2wi.c
Original file line number Diff line number Diff line change
@@ -234,7 +234,7 @@ static int p2wi_probe(struct platform_device *pdev)
if (IS_ERR(p2wi->regs))
return PTR_ERR(p2wi->regs);

strlcpy(p2wi->adapter.name, pdev->name, sizeof(p2wi->adapter.name));
strscpy(p2wi->adapter.name, pdev->name, sizeof(p2wi->adapter.name));
irq = platform_get_irq(pdev, 0);
if (irq < 0)
return irq;

0 comments on commit e47a0ce

Please sign in to comment.