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);
 }
 
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to