svn commit: r288915 - head/usr.sbin/rpcbind

Hiroki Sato hrs at FreeBSD.org
Tue Oct 6 08:43:50 UTC 2015


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);
 }
 


More information about the svn-src-all mailing list