[OpenWrt-Devel] [PATCH] use strncpy instead of strcpy

Khem Raj raj.khem at gmail.com
Tue Dec 24 15:14:11 EST 2019


On Tue, Dec 24, 2019 at 10:10 AM Paul Fertser <fercerpav at gmail.com> wrote:

> Hi,
>
> On Tue, Dec 24, 2019 at 10:02:13AM -0800, Khem Raj wrote:
> > +     hdr->name[strlen((char*)hdr->name)] = '\0';
> > +     strncpy((char *) hdr->name, (const char *)name,
> strlen((char*)hdr->name));
>
> strlen((char*)hdr->name) doesn't seem to be meaningful in this
> context, are you sure you were not meaning to do something like this
> instead?
>
> +       strncpy((char *) hdr->name, (const char *)name, sizeof(hdr->name));
> +       hdr->name[sizeof(hdr->name) - 1] = '\0';


Yes that is better I will send a v2 after tests

>
>
> --
> Be free, use free (http://www.gnu.org/philosophy/free-sw.html) software!
> mailto:fercerpav at gmail.com
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.infradead.org/pipermail/openwrt-devel/attachments/20191224/2c86a00d/attachment.htm>
-------------- next part --------------
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


More information about the openwrt-devel mailing list