From owner-svn-src-all@freebsd.org Tue Oct 6 08:43:49 2015 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id E15FA9B68F5; Tue, 6 Oct 2015 08:43:49 +0000 (UTC) (envelope-from hrs@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id D2AEE254; Tue, 6 Oct 2015 08:43:49 +0000 (UTC) (envelope-from hrs@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.70]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t968hnbi071469; Tue, 6 Oct 2015 08:43:49 GMT (envelope-from hrs@FreeBSD.org) Received: (from hrs@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id t968hnlk071468; Tue, 6 Oct 2015 08:43:49 GMT (envelope-from hrs@FreeBSD.org) Message-Id: <201510060843.t968hnlk071468@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hrs set sender to hrs@FreeBSD.org using -f From: Hiroki Sato Date: Tue, 6 Oct 2015 08:43:49 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r288915 - head/usr.sbin/rpcbind X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.20 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: Tue, 06 Oct 2015 08:43:50 -0000 Author: hrs Date: Tue Oct 6 08:43:48 2015 New Revision: 288915 URL: https://svnweb.freebsd.org/changeset/base/288915 Log: Reallocate a maxlen-long buffer only when the current maxlen is shorter than the required length. Note that it rarely happens because maxlen is almost always 128 which covers struct sockaddr_storage. Modified: head/usr.sbin/rpcbind/rpcb_svc_com.c Modified: head/usr.sbin/rpcbind/rpcb_svc_com.c ============================================================================== --- head/usr.sbin/rpcbind/rpcb_svc_com.c Tue Oct 6 07:46:19 2015 (r288914) +++ head/usr.sbin/rpcbind/rpcb_svc_com.c Tue Oct 6 08:43:48 2015 (r288915) @@ -1051,17 +1051,19 @@ netbufcmp(struct netbuf *n1, struct netb static bool_t netbuf_copybuf(struct netbuf *dst, const struct netbuf *src) { + assert(src->len <= src->maxlen); - if (dst->len != src->len || dst->buf == NULL) { + if (dst->maxlen < src->len || dst->buf == NULL) { if (dst->buf != NULL) free(dst->buf); - if ((dst->buf = malloc(src->len)) == NULL) + if ((dst->buf = calloc(1, src->maxlen)) == NULL) return (FALSE); - - dst->maxlen = dst->len = src->len; + dst->maxlen = src->maxlen; } + dst->len = src->len; memcpy(dst->buf, src->buf, src->len); + return (TRUE); }