From owner-svn-src-all@FreeBSD.ORG Thu May 28 21:52:01 2009 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id BAEB610656CA; Thu, 28 May 2009 21:52:01 +0000 (UTC) (envelope-from delphij@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 6E24D8FC1E; Thu, 28 May 2009 21:52:01 +0000 (UTC) (envelope-from delphij@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n4SLq1Tl050971; Thu, 28 May 2009 21:52:01 GMT (envelope-from delphij@svn.freebsd.org) Received: (from delphij@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n4SLq1ex050970; Thu, 28 May 2009 21:52:01 GMT (envelope-from delphij@svn.freebsd.org) Message-Id: <200905282152.n4SLq1ex050970@svn.freebsd.org> From: Xin LI Date: Thu, 28 May 2009 21:52:01 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-7@freebsd.org X-SVN-Group: stable-7 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r192999 - in stable/7/lib/libc: . gen string 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: Thu, 28 May 2009 21:52:05 -0000 Author: delphij Date: Thu May 28 21:52:00 2009 New Revision: 192999 URL: http://svn.freebsd.org/changeset/base/192999 Log: Merge r192129+r190661: Properly handle malloc() failures. PR: bin/83338 Modified: stable/7/lib/libc/ (props changed) stable/7/lib/libc/gen/getcap.c stable/7/lib/libc/string/ffsll.c (props changed) stable/7/lib/libc/string/flsll.c (props changed) Modified: stable/7/lib/libc/gen/getcap.c ============================================================================== --- stable/7/lib/libc/gen/getcap.c Thu May 28 21:41:01 2009 (r192998) +++ stable/7/lib/libc/gen/getcap.c Thu May 28 21:52:00 2009 (r192999) @@ -189,7 +189,7 @@ getent(char **cap, u_int *len, char **db { DB *capdbp; char *r_end, *rp, **db_p; - int myfd, eof, foundit, retval, clen; + int myfd, eof, foundit, retval; char *record, *cbuf; int tc_not_resolved; char pbuf[_POSIX_PATH_MAX]; @@ -251,14 +251,16 @@ getent(char **cap, u_int *len, char **db return (retval); } /* save the data; close frees it */ - clen = strlen(record); - cbuf = malloc(clen + 1); - memcpy(cbuf, record, clen + 1); + cbuf = strdup(record); if (capdbp->close(capdbp) < 0) { free(cbuf); return (-2); } - *len = clen; + if (cbuf == NULL) { + errno = ENOMEM; + return (-2); + } + *len = strlen(cbuf); *cap = cbuf; return (retval); } else {