From owner-svn-src-all@FreeBSD.ORG Fri Dec 23 02:13:42 2011 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 726021065670; Fri, 23 Dec 2011 02:13:42 +0000 (UTC) (envelope-from ghelmer@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 536AF8FC0C; Fri, 23 Dec 2011 02:13:42 +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 pBN2DgUX043640; Fri, 23 Dec 2011 02:13:42 GMT (envelope-from ghelmer@svn.freebsd.org) Received: (from ghelmer@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id pBN2DgIa043638; Fri, 23 Dec 2011 02:13:42 GMT (envelope-from ghelmer@svn.freebsd.org) Message-Id: <201112230213.pBN2DgIa043638@svn.freebsd.org> From: Guy Helmer Date: Fri, 23 Dec 2011 02:13:42 +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: r228828 - head/lib/libc/yp 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: Fri, 23 Dec 2011 02:13:42 -0000 Author: ghelmer Date: Fri Dec 23 02:13:42 2011 New Revision: 228828 URL: http://svn.freebsd.org/changeset/base/228828 Log: Handle malloc failures in yplib.c. PR: bin/83349 Modified: head/lib/libc/yp/yplib.c Modified: head/lib/libc/yp/yplib.c ============================================================================== --- head/lib/libc/yp/yplib.c Fri Dec 23 02:04:35 2011 (r228827) +++ head/lib/libc/yp/yplib.c Fri Dec 23 02:13:42 2011 (r228828) @@ -331,6 +331,8 @@ _yp_dobind(char *dom, struct dom_binding if (ysd == NULL) { ysd = (struct dom_binding *)malloc(sizeof *ysd); + if (ysd == NULL) + return (YPERR_RESRC); bzero((char *)ysd, sizeof *ysd); ysd->dom_socket = -1; ysd->dom_vers = 0; @@ -683,11 +685,18 @@ yp_match(char *indomain, char *inmap, co */ *outvallen = yprv.val.valdat_len; *outval = (char *)malloc(*outvallen+1); + if (*outval == NULL) { + _yp_unbind(ysd); + *outvallen = 0; + YPUNLOCK(); + return (YPERR_RESRC); + } bcopy(yprv.val.valdat_val, *outval, *outvallen); (*outval)[*outvallen] = '\0'; YPUNLOCK(); return (0); } + _yp_unbind(ysd); #endif again: @@ -713,6 +722,13 @@ again: if (!(r = ypprot_err(yprv.stat))) { *outvallen = yprv.val.valdat_len; *outval = (char *)malloc(*outvallen+1); + if (*outval == NULL) { + _yp_unbind(ysd); + *outvallen = 0; + xdr_free((xdrproc_t)xdr_ypresp_val, &yprv); + YPUNLOCK(); + return (YPERR_RESRC); + } bcopy(yprv.val.valdat_val, *outval, *outvallen); (*outval)[*outvallen] = '\0'; #ifdef YPMATCHCACHE @@ -791,10 +807,25 @@ again: if (!(r = ypprot_err(yprkv.stat))) { *outkeylen = yprkv.key.keydat_len; *outkey = (char *)malloc(*outkeylen+1); + if (*outkey == NULL) { + _yp_unbind(ysd); + *outkeylen = 0; + xdr_free((xdrproc_t)xdr_ypresp_key_val, &yprkv); + YPUNLOCK(); + return (YPERR_RESRC); + } bcopy(yprkv.key.keydat_val, *outkey, *outkeylen); (*outkey)[*outkeylen] = '\0'; *outvallen = yprkv.val.valdat_len; *outval = (char *)malloc(*outvallen+1); + if (*outval == NULL) { + free(*outkey); + _yp_unbind(ysd); + *outkeylen = *outvallen = 0; + xdr_free((xdrproc_t)xdr_ypresp_key_val, &yprkv); + YPUNLOCK(); + return (YPERR_RESRC); + } bcopy(yprkv.val.valdat_val, *outval, *outvallen); (*outval)[*outvallen] = '\0'; } @@ -851,10 +882,25 @@ again: if (!(r = ypprot_err(yprkv.stat))) { *outkeylen = yprkv.key.keydat_len; *outkey = (char *)malloc(*outkeylen+1); + if (*outkey == NULL) { + _yp_unbind(ysd); + *outkeylen = 0; + xdr_free((xdrproc_t)xdr_ypresp_key_val, &yprkv); + YPUNLOCK(); + return (YPERR_RESRC); + } bcopy(yprkv.key.keydat_val, *outkey, *outkeylen); (*outkey)[*outkeylen] = '\0'; *outvallen = yprkv.val.valdat_len; *outval = (char *)malloc(*outvallen+1); + if (*outval == NULL) { + free(*outkey); + _yp_unbind(ysd); + *outkeylen = *outvallen = 0; + xdr_free((xdrproc_t)xdr_ypresp_key_val, &yprkv); + YPUNLOCK(); + return (YPERR_RESRC); + } bcopy(yprkv.val.valdat_val, *outval, *outvallen); (*outval)[*outvallen] = '\0'; }