Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 6 Oct 2015 08:43:49 +0000 (UTC)
From:      Hiroki Sato <hrs@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r288915 - head/usr.sbin/rpcbind
Message-ID:  <201510060843.t968hnlk071468@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
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);
 }
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201510060843.t968hnlk071468>