From owner-freebsd-hackers@FreeBSD.ORG Fri May 18 22:17:47 2012 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 9062B106564A for ; Fri, 18 May 2012 22:17:47 +0000 (UTC) (envelope-from ghelmer@palisadesys.com) Received: from ps-1-b.compliancesafe.com (ps-1-b.compliancesafe.com [216.81.161.162]) by mx1.freebsd.org (Postfix) with ESMTP id 468D08FC0A for ; Fri, 18 May 2012 22:17:46 +0000 (UTC) Received: from mail.palisadesystems.com (localhost [127.0.0.1]) by ps-1-b.compliancesafe.com (8.14.4/8.14.3) with ESMTP id q4IM6xsW087636 for ; Fri, 18 May 2012 17:06:59 -0500 (CDT) (envelope-from ghelmer@palisadesys.com) Received: from guysmbp.dyn.palisadesys.com (GuysMBP.dyn.palisadesys.com [172.16.2.90]) (authenticated bits=0) by mail.palisadesystems.com (8.14.3/8.14.3) with ESMTP id q4ILwh8Y049732 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NO) for ; Fri, 18 May 2012 16:58:43 -0500 (CDT) (envelope-from ghelmer@palisadesys.com) X-DKIM: Sendmail DKIM Filter v2.8.3 mail.palisadesystems.com q4ILwh8Y049732 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=palisadesys.com; s=mail; t=1337378323; bh=Jxga24JsyWMcgrQ7bt9QGudJRY09JZf9VdZ+DbKDOHY=; l=128; h=From:Content-Type:Content-Transfer-Encoding:Subject:Date: Message-Id:To:Mime-Version; b=jH9hBa6PDBWGnCthO1s+bIh2jyTvmMHz4kzMBIsLXuYJoEw9oPBWTYFqZG58OF4YY NedVPhnOp2FH41JhqRniI69FGSN9cKNot7CJfswW37u6YkfggDPvhRoOYGWADN9GDY S+Q6gvNHd4sIZcRMjdEzpR5EbY05CM8Ei8N/krJ8= From: Guy Helmer Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Date: Fri, 18 May 2012 16:58:42 -0500 Message-Id: <4EE466CC-5F93-485C-8E1F-907F8049FD61@palisadesys.com> To: freebsd-hackers@freebsd.org Mime-Version: 1.0 (Apple Message framework v1278) X-Mailer: Apple Mail (2.1278) X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.5 (mail.palisadesystems.com [172.16.1.5]); Fri, 18 May 2012 16:58:43 -0500 (CDT) X-Palisade-MailScanner-Information: Please contact the ISP for more information X-Palisade-MailScanner-ID: q4ILwh8Y049732 X-Palisade-MailScanner: Found to be clean X-Palisade-MailScanner-SpamCheck: not spam (whitelisted), SpamAssassin (score=2.084, required 5, ALL_TRUSTED -1.00, BAYES_00 -1.90, J_CHICKENPOX_53 0.60, J_CHICKENPOX_54 0.60, J_CHICKENPOX_56 0.60, J_CHICKENPOX_63 0.60, J_CHICKENPOX_92 0.60, RP_8BIT 1.98) X-Palisade-MailScanner-From: ghelmer@palisadesys.com X-Spam-Status: No X-PacketSure-Scanned: Yes Subject: Review of changes for getnetgrent.c X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 May 2012 22:17:47 -0000 To close PR bin/83340, I have this change worked up to resolve memory = allocation failure handling and avoid creating bad entries in the grp = list due to memory allocation failures while building a new entry. Before committing, I wanted to run it past others to see if there were = any problems with it. Thanks, Guy > svn diff lib/libc/gen Index: lib/libc/gen/getnetgrent.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- lib/libc/gen/getnetgrent.c (revision 235606) +++ lib/libc/gen/getnetgrent.c (working copy) @@ -203,9 +203,7 @@ if (parse_netgrp(group)) endnetgrent(); else { - grouphead.grname =3D (char *) - malloc(strlen(group) + 1); - strcpy(grouphead.grname, group); + grouphead.grname =3D strdup(group); } if (netf) fclose(netf); @@ -417,7 +415,7 @@ parse_netgrp(const char *group) { char *spos, *epos; - int len, strpos; + int len, strpos, freepos; #ifdef DEBUG int fields; #endif @@ -454,9 +452,9 @@ while (pos !=3D NULL && *pos !=3D '\0') { if (*pos =3D=3D '(') { grp =3D (struct netgrp *)malloc(sizeof (struct = netgrp)); + if (grp =3D=3D NULL) + return(1); bzero((char *)grp, sizeof (struct netgrp)); - grp->ng_next =3D grouphead.gr; - grouphead.gr =3D grp; pos++; gpos =3D strsep(&pos, ")"); #ifdef DEBUG @@ -477,6 +475,13 @@ if (len > 0) { grp->ng_str[strpos] =3D = (char *) malloc(len + 1); + if (grp->ng_str[strpos] = =3D=3D NULL) { + for (freepos =3D = 0; freepos < strpos; freepos++) + if = (grp->ng_str[freepos] !=3D NULL) + = free(grp->ng_str[freepos]); + free(grp); + return(1); + } bcopy(spos, = grp->ng_str[strpos], len + 1); } @@ -490,6 +495,8 @@ grp->ng_str[strpos] =3D NULL; } } + grp->ng_next =3D grouphead.gr; + grouphead.gr =3D grp; #ifdef DEBUG /* * Note: on other platforms, malformed netgroup @@ -526,7 +533,7 @@ static struct linelist * read_for_group(const char *group) { - char *pos, *spos, *linep, *olinep; + char *pos, *spos, *linep; int len, olen; int cont; struct linelist *lp; @@ -534,6 +541,7 @@ #ifdef YP char *result; int resultlen; + linep =3D NULL; =20 while (_netgr_yp_enabled || fgets(line, LINSIZ, netf) !=3D NULL) = { if (_netgr_yp_enabled) { @@ -554,6 +562,7 @@ free(result); } #else + linep =3D NULL; while (fgets(line, LINSIZ, netf) !=3D NULL) { #endif pos =3D (char *)&line; @@ -576,8 +585,14 @@ pos++; if (*pos !=3D '\n' && *pos !=3D '\0') { lp =3D (struct linelist *)malloc(sizeof (*lp)); + if (lp =3D=3D NULL)=20 + return(NULL); lp->l_parsed =3D 0; lp->l_groupname =3D (char *)malloc(len + 1); + if (lp->l_groupname =3D=3D NULL) { + free(lp); + return(NULL); + } bcopy(spos, lp->l_groupname, len); *(lp->l_groupname + len) =3D '\0'; len =3D strlen(pos); @@ -595,15 +610,15 @@ } 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 (char = *)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)) { @@ -634,5 +649,5 @@ */ rewind(netf); #endif - return ((struct linelist *)0); + return (NULL); } -------- This message has been scanned by ComplianceSafe, powered by Palisade's PacketSure.