From owner-svn-src-all@FreeBSD.ORG Sat Jun 16 13:10:23 2012 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 281851065763; Sat, 16 Jun 2012 13:10:23 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 08F8D8FC14; Sat, 16 Jun 2012 13:10:23 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q5GDAMBH045749; Sat, 16 Jun 2012 13:10:22 GMT (envelope-from kib@svn.freebsd.org) Received: (from kib@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q5GDAMlC045747; Sat, 16 Jun 2012 13:10:22 GMT (envelope-from kib@svn.freebsd.org) Message-Id: <201206161310.q5GDAMlC045747@svn.freebsd.org> From: Konstantin Belousov Date: Sat, 16 Jun 2012 13:10:22 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r237159 - head/lib/libc/gen X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 16 Jun 2012 13:10:23 -0000 Author: kib Date: Sat Jun 16 13:10:22 2012 New Revision: 237159 URL: http://svn.freebsd.org/changeset/base/237159 Log: Revert part of the r235740 which changed separate allocation of the string buffer for each linelist l_line into one large string. Since linelists parsed out during the previous passes store the pointers to previously allocated l_lines, the reallocation caused undefined behaviour on accessing the buffers, and quite deterministic fault on freeing them (in mountd(8) startup). This fixes reading of netgroup(5) file which contains more then one netgroup. Discussed with: ghelmer MFC after: 3 days Modified: head/lib/libc/gen/getnetgrent.c Modified: head/lib/libc/gen/getnetgrent.c ============================================================================== --- head/lib/libc/gen/getnetgrent.c Sat Jun 16 12:56:36 2012 (r237158) +++ head/lib/libc/gen/getnetgrent.c Sat Jun 16 13:10:22 2012 (r237159) @@ -538,7 +538,7 @@ parse_netgrp(const char *group) static struct linelist * read_for_group(const char *group) { - char *pos, *spos, *linep; + char *linep, *olinep, *pos, *spos; int len, olen; int cont; struct linelist *lp; @@ -615,15 +615,20 @@ read_for_group(const char *group) } else cont = 0; if (len > 0) { - linep = reallocf(linep, olen + len + 1); + linep = malloc(olen + len + 1); if (linep == NULL) { free(lp->l_groupname); free(lp); return (NULL); } + if (olen > 0) { + bcopy(olinep, linep, olen); + free(olinep); + } bcopy(pos, linep + olen, len); olen += len; *(linep + olen) = '\0'; + olinep = linep; } if (cont) { if (fgets(line, LINSIZ, netf)) {