From owner-svn-src-stable-9@FreeBSD.ORG Fri Jun 15 23:02:39 2012 Return-Path: Delivered-To: svn-src-stable-9@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 465ED106566B; Fri, 15 Jun 2012 23:02:39 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from mail.zoral.com.ua (mx0.zoral.com.ua [91.193.166.200]) by mx1.freebsd.org (Postfix) with ESMTP id B6B248FC0A; Fri, 15 Jun 2012 23:02:38 +0000 (UTC) Received: from skuns.kiev.zoral.com.ua (localhost [127.0.0.1]) by mail.zoral.com.ua (8.14.2/8.14.2) with ESMTP id q5FN2PFa086395; Sat, 16 Jun 2012 02:02:25 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: from deviant.kiev.zoral.com.ua (kostik@localhost [127.0.0.1]) by deviant.kiev.zoral.com.ua (8.14.5/8.14.5) with ESMTP id q5FN2Otj036027; Sat, 16 Jun 2012 02:02:24 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: (from kostik@localhost) by deviant.kiev.zoral.com.ua (8.14.5/8.14.5/Submit) id q5FN2O3S036026; Sat, 16 Jun 2012 02:02:24 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: deviant.kiev.zoral.com.ua: kostik set sender to kostikbel@gmail.com using -f Date: Sat, 16 Jun 2012 02:02:24 +0300 From: Konstantin Belousov To: Guy Helmer Message-ID: <20120615230224.GI2337@deviant.kiev.zoral.com.ua> References: <201206142148.q5ELmFul023002@svn.freebsd.org> <20120615212651.GH2337@deviant.kiev.zoral.com.ua> <880C698D-7620-48CB-B0EB-68BBC7FECDBB@palisadesystems.com> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="OtZJUqNUNrB9XA/T" Content-Disposition: inline In-Reply-To: <880C698D-7620-48CB-B0EB-68BBC7FECDBB@palisadesystems.com> User-Agent: Mutt/1.4.2.3i X-Virus-Scanned: clamav-milter 0.95.2 at skuns.kiev.zoral.com.ua X-Virus-Status: Clean X-Spam-Status: No, score=-4.0 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on skuns.kiev.zoral.com.ua Cc: svn-src-stable@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org, svn-src-stable-9@freebsd.org Subject: Re: svn commit: r237106 - stable/9/lib/libc/gen X-BeenThere: svn-src-stable-9@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for only the 9-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 15 Jun 2012 23:02:39 -0000 --OtZJUqNUNrB9XA/T Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Jun 15, 2012 at 05:33:27PM -0500, Guy Helmer wrote: >=20 > On Jun 15, 2012, at 4:26 PM, Konstantin Belousov wrote: >=20 > > On Thu, Jun 14, 2012 at 09:48:15PM +0000, Guy Helmer wrote: > >> Author: ghelmer > >> Date: Thu Jun 14 21:48:14 2012 > >> New Revision: 237106 > >> URL: http://svn.freebsd.org/changeset/base/237106 > >>=20 > >> Log: > >> MFC 235739-235740,236402: > >> Apply style(9) to return and switch/case statements. > >>=20 > >> Add checks for memory allocation failures in appropriate places, and > >> avoid creating bad entries in the grp list as a result of memory allo= cation > >> failures while building new entries. > >>=20 > >> Style(9) improvements: remove unnecessary parenthesis, improve order > >> of local variable declarations, remove bogus casts, and resolve long > >> lines. > >>=20 > >> PR: bin/83340 > >>=20 > >> Modified: > >> stable/9/lib/libc/gen/getnetgrent.c > >> Directory Properties: > >> stable/9/lib/libc/ (props changed) > >>=20 > > This broke mountd(8) for me. It dies with SIGSEGV on start. Autopsy has > > shown that this happen due to free(3) on an unallocated pointer. > >=20 > > I have two netgroups in my /etc/netgroup: > > testboxes (solo.home, , ) (x.home, , ) (nv.home, , ) (sandy.home, , ) (= tom.home, ,) > > laptops (alf.home, , ) (alf.home-air, , ) (sirion.home, , ) (sirion.hom= e-air, , ) > >=20 > > The http://people.freebsd.org/~kib/misc/netgr.c shows the issue. Run it > > as "netgr testboxes laptops". > >=20 > > Your change below makes lp->l_lines pointer for already processed groups > > invalid because you reallocf(3) the memory pointed by it. Then > > 1. accessing the l_lines later causes undefined behaviour; > > 2. free(3) call in endnetgrent() dies because pointer is dandling. > >=20 > >> @@ -595,15 +615,15 @@ read_for_group(const char *group) > >> } else > >> cont =3D 0; > >> if (len > 0) { > >> - linep =3D (char *)malloc(olen + len + 1); > >> - if (olen > 0) { > >> - bcopy(olinep, linep, olen); > >> - free(olinep); > >> + linep =3D reallocf(linep, olen + len + 1); > >> + if (linep =3D=3D NULL) { > >> + free(lp->l_groupname); > >> + free(lp); > >> + return (NULL); > >> } > >> bcopy(pos, linep + olen, len); > >> olen +=3D len; > >> *(linep + olen) =3D '\0'; > >> - olinep =3D linep; > >> } > >> if (cont) { > >> if (fgets(line, LINSIZ, netf)) { > >=20 > > Below is partial revert of your changes that cures mountd for me. Also, > > the second patch does some further cleanup of the getnetgrent.c. > >=20 > > Do you agree ? >=20 > Sorry for the breakage. FWIW, I am having difficulty seeing how: >=20 > linep =3D malloc(olen + len + 1); > ? > if (olen > 0) { > bcopy(olinep, linep, olen); > free(olinep); > } >=20 > is different from: >=20 > linep =3D reallocf(linep, olen + len + 1); >=20 The old value of linep is invalid after the call to reallocf() and must be not used further. But it is saved as l_line value, so it gets free()d. You de-facto use very long line, containing lines for all groups, with l_line pointing in the middle of it. It is some luck that in my case reallocf() was able to extend original chunk, otherwise I would also get garbage in l_lines. >=20 > but if it fixes the issue, it is good. I would beware the disorder in the= sorting of the variables in the line: >=20 > char *pos, *spos, *linep, *olinep;". Fixed. --OtZJUqNUNrB9XA/T Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (FreeBSD) iEYEARECAAYFAk/bvwAACgkQC3+MBN1Mb4hrHwCfZuxLndQKUvjGXpuROMnTrxlg 9AoAn3Q7rGBlwe6Xkpk9hhancGAtFP4R =JoUY -----END PGP SIGNATURE----- --OtZJUqNUNrB9XA/T--