Date: Sat, 31 Jan 2004 14:50:14 -0800 From: Brooks Davis <brooks@one-eyed-alien.net> To: Peter Jeremy <PeterJeremy@optushome.com.au> Cc: cvs-all@freebsd.org Subject: Re: cvs commit: src/sbin/ifconfig ifconfig.c ifconfig.h Message-ID: <20040131225013.GA14981@Odin.AC.HMC.Edu> In-Reply-To: <20040131201747.GO908@cirb503493.alcatel.com.au> References: <200401270143.i0R1hEIO011023@repoman.freebsd.org> <20040129133342.GC19899@FreeBSD.org.ua> <20040131201747.GO908@cirb503493.alcatel.com.au>
next in thread | previous in thread | raw e-mail | index | archive | help
--WIyZ46R2i8wDzkSu Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Feb 01, 2004 at 07:17:48AM +1100, Peter Jeremy wrote: > On Mon, Jan 26, 2004 at 05:43:14PM -0800, Brooks Davis wrote: > > brooks 2004/01/26 17:43:14 PST > >=20 > > FreeBSD src repository > >=20 > > Modified files: > > sbin/ifconfig ifconfig.c ifconfig.h=20 > > Log: > > Use IFNAMSIZ instead of a magic value for the length of an interface > > name. > > =20 > > Prevent the kernel from potentially overflowing the interface name > > variable. The size argument of strlcpy is complex because the name is > > not null-terminated in sdl_data. >=20 > Based on this comment and a quick look at the code change, I don't believe > this change is correct. The source argument to strlcpy(3) _must_ be NUL > terminated - although strlcpy() will only copy the specified number of > characters, it will traverse the source argument until it finds a NUL > character so it can return the size of the source argument. In this case, > sdl_data is not intentionally NUL terminated so the strlcpy() can scan > forward over an arbitrary amount of process address space until stopped > by a random NUL, SIGBUS or SIGSEGV. The latter two possibilities are > undesirable :-). >=20 > In this case, I believe the correct code is something like: > memcpy(name, sdl->sdl_data, sizeof(name) < sdl->sdl_nlen ? > sizeof(name)-1 : sdl->sdl_nlen); > name[sizeof(name) < sdl->sdl_nlen ? sizeof(name)-1 : sdl->sdl_nlen] > =3D '\0'; > (strncpy could be used in place of memcpy). You are correct. I forgot about that issue. I'll commit this fix soon. On the plus side, this won't actually happen with real interfaces because the minimum size of sdl_data is larger then is actually needed by any interface I've found so in practice you will hit a NUL after the address. -- Brooks --=20 Any statement of the form "X is the one, true Y" is FALSE. PGP fingerprint 655D 519C 26A7 82E7 2529 9BF0 5D8E 8BE9 F238 1AD4 --WIyZ46R2i8wDzkSu Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (GNU/Linux) iD8DBQFAHDElXY6L6fI4GtQRAiTjAJ9YKF8St+/XpXHlxtxqquMC/4ji2gCgkTN3 D+eMdAq7KF0sNAseXZabu4Y= =eEUH -----END PGP SIGNATURE----- --WIyZ46R2i8wDzkSu--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040131225013.GA14981>