2003-11-27 14:05:34

by Felipe Alfaro Solana

[permalink] [raw]
Subject: [PATCH 2.6]: IPv4: strcpy -> strlcpy

Hi!

Attached is a patch to replace strcpy() calls with strlcpy() for IPv4.
Compiled and tested. Please, consider applying.

Thanks!


Attachments:
strlcpy-ipv4.patch (8.72 kB)

2003-11-27 14:21:31

by David Roundy

[permalink] [raw]
Subject: Re: [PATCH 2.6]: IPv4: strcpy -> strlcpy

On Thu, Nov 27, 2003 at 03:04:42PM +0100, Felipe Alfaro Solana wrote:
> diff -uNr linux-2.6.0-test11.orig/net/core/dev.c linux-2.6.0-test11/net/core/dev.c
> +++ linux-2.6.0-test11/net/core/dev.c 2003-11-27 13:21:12.791315993 +0100
> @@ -335,7 +335,7 @@
> for (i = 0; i < NETDEV_BOOT_SETUP_MAX; i++) {
> if (s[i].name[0] == '\0' || s[i].name[0] == ' ') {
> memset(s[i].name, 0, sizeof(s[i].name));
> - strcpy(s[i].name, name);
> + strlcpy(s[i].name, name, sizeof(s[i].map));
^^^
I believe this should be name.
--
David Roundy
http://www.abridgegame.org

2003-11-27 15:26:07

by Felipe Alfaro Solana

[permalink] [raw]
Subject: Re: [PATCH 2.6]: IPv4: strcpy -> strlcpy

On Thu, 2003-11-27 at 15:21, David Roundy wrote:
> On Thu, Nov 27, 2003 at 03:04:42PM +0100, Felipe Alfaro Solana wrote:
> > diff -uNr linux-2.6.0-test11.orig/net/core/dev.c linux-2.6.0-test11/net/core/dev.c
> > +++ linux-2.6.0-test11/net/core/dev.c 2003-11-27 13:21:12.791315993 +0100
> > @@ -335,7 +335,7 @@
> > for (i = 0; i < NETDEV_BOOT_SETUP_MAX; i++) {
> > if (s[i].name[0] == '\0' || s[i].name[0] == ' ') {
> > memset(s[i].name, 0, sizeof(s[i].name));
> > - strcpy(s[i].name, name);
> > + strlcpy(s[i].name, name, sizeof(s[i].map));
> ^^^
> I believe this should be name.

Yes, you're right. Sorry, my fault.
Corrected patch attached.
Thanks!


Attachments:
strlcpy-ipv4.patch (8.72 kB)

2003-11-27 20:48:17

by Timo Kamph

[permalink] [raw]
Subject: Re: [PATCH 2.6]: IPv4: strcpy -> strlcpy

On 27 Nov 2003 at 16:25, Felipe Alfaro Solana wrote:

> --- linux-2.6.0-test11.orig/net/ipv4/netfilter/ipchains_core.c 2003-11-26 21:45:26.000000000 +0100
> +++ linux-2.6.0-test11/net/ipv4/netfilter/ipchains_core.c 2003-11-27 13:28:39.884442527 +0100
> @@ -1173,7 +1173,7 @@
> = kmalloc(SIZEOF_STRUCT_IP_CHAIN, GFP_KERNEL);
> if (label == NULL)
> panic("Can't kmalloc for firewall chains.\n");
> - strcpy(label->label,name);
> + strlcpy(label->label, name, sizeof(label->name));
^^^^^^
I guess this shoud be label->label, or am I wrong?

Timo

2003-11-27 22:09:36

by Felipe Alfaro Solana

[permalink] [raw]
Subject: Re: [PATCH 2.6]: IPv4: strcpy -> strlcpy

On Thu, 2003-11-27 at 21:48, Timo Kamph wrote:

> > + strlcpy(label->label, name, sizeof(label->name));
> ^^^^^^
> I guess this shoud be label->label, or am I wrong?

Oh my god! Two consecutive mistakes with the same patch! I should have
some sleep... Here's the one with the typo corrected.

Thanks for pointing it out. Sorry for resending this patch so many
times.


Attachments:
strlcpy-ipv4.patch (8.72 kB)

2003-11-28 02:05:49

by YOSHIFUJI Hideaki

[permalink] [raw]
Subject: Re: [PATCH 2.6]: IPv4: strcpy -> strlcpy

In article <[email protected]> (at Thu, 27 Nov 2003 23:09:06 +0100), Felipe Alfaro Solana <[email protected]> says:

> diff -uNr linux-2.6.0-test11.orig/net/ipv4/ipconfig.c linux-2.6.0-test11/net/ipv4/ipconfig.c
> --- linux-2.6.0-test11.orig/net/ipv4/ipconfig.c 2003-11-26 21:42:55.000000000 +0100
> +++ linux-2.6.0-test11/net/ipv4/ipconfig.c 2003-11-27 13:32:06.904650818 +0100
> @@ -299,7 +299,7 @@
> int err;
>
> memset(&ir, 0, sizeof(ir));
> - strcpy(ir.ifr_ifrn.ifrn_name, ic_dev->name);
> + strlcpy(ir.ifr_ifrn.ifrn_name, ic_dev->name, sizeof(ir.ifr_ifrn.ifrn_name));

please use
strlcpy(ir.ifr_name, ic_dev->name, sizeof(ir.ifr_name));
instead.

--yoshfuji

2003-11-28 09:42:25

by David Woodhouse

[permalink] [raw]
Subject: Re: [PATCH 2.6]: IPv4: strcpy -> strlcpy

On Thu, 2003-11-27 at 23:09 +0100, Felipe Alfaro Solana wrote:
> On Thu, 2003-11-27 at 21:48, Timo Kamph wrote:
>
> > > + strlcpy(label->label, name, sizeof(label->name));
> > ^^^^^^
> > I guess this shoud be label->label, or am I wrong?
>
> Oh my god! Two consecutive mistakes with the same patch! I should have
> some sleep... Here's the one with the typo corrected.

Perhaps we should consider

#define strsizecpy(x, y) strlcpy((x), (y), sizeof(x))

--
dwmw2

2003-11-30 10:57:01

by Ingo Oeser

[permalink] [raw]
Subject: Re: [PATCH 2.6]: IPv4: strcpy -> strlcpy

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Friday 28 November 2003 10:42, David Woodhouse wrote:
> On Thu, 2003-11-27 at 23:09 +0100, Felipe Alfaro Solana wrote:
> > On Thu, 2003-11-27 at 21:48, Timo Kamph wrote:
> > > > + strlcpy(label->label, name, sizeof(label->name));
> > >
> > >
> > > ^^^^^^ I guess this shoud be label->label, or am I wrong?
> >
> > Oh my god! Two consecutive mistakes with the same patch! I should have
> > some sleep... Here's the one with the typo corrected.
>
> Perhaps we should consider
>
> #define strsizecpy(x, y) strlcpy((x), (y), sizeof(x))

Then we should do:

#define strsizecpy(x, y) strlcpy(x, y, sizeof(x)/sizeof(x[0]))

to rule out passing the wrong variables or dereferencing to much.

Unfortunatly there is no simple way in C to differentiate between array and
pointer.

There is a way with typeof, but that is hackish.


Regards

Ingo Oeser

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQE/ycXOU56oYWuOrkARAiJ8AJ9wkl1ijJVn5M+lGhUwSwWRxzxxHwCg2nAU
t+9HdAasQDZo/GQFuj9s5ZU=
=py/4
-----END PGP SIGNATURE-----