Thread (9 messages) 9 messages, 5 authors, 2021-08-10

Re: [PATCH v2] drivers/iio: Remove all strcpy() uses in favor of strscpy()

From: Andy Shevchenko <hidden>
Date: 2021-08-10 12:11:41
Also in: linux-hardening, lkml

On Tue, Aug 10, 2021 at 3:06 PM Andy Shevchenko
[off-list ref] wrote:
On Mon, Aug 9, 2021 at 7:14 PM Len Baker [off-list ref] wrote:

Even if we leave the logic as is, this might be better

if (orient[0] == '-')
   str = devm_kstrdup(dev, orient + 1, GFP_KERNEL);
else if (orient[0] != '0' || orient[1] != '\0')
   str = devm_kasprintf(dev, GFP_KERNEL, "-%s", orient);
else
   str = devm_kstrdup(dev, orient, GFP_KERNEL);
Or these two swapped for better reading

 else if (orient[0] == '0' **&& orient[1] == '\0')
    str = devm_kstrdup(dev, orient, GFP_KERNEL);
else
    str = devm_kasprintf(dev, GFP_KERNEL, "-%s", orient);

And with a comment added that we negate the result according to the
rules: 1) drop leading '-' (minus); 2) leave 0 as is; add leading '-'
(minus).
if (!str)
   return -ENOMEM;


-- 
With Best Regards,
Andy Shevchenko
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help