diff options
author | hrs <hrs@FreeBSD.org> | 2015-10-06 08:43:48 +0000 |
---|---|---|
committer | hrs <hrs@FreeBSD.org> | 2015-10-06 08:43:48 +0000 |
commit | a9bfaebd85834b2174fc8556e888c5dc381ace2f (patch) | |
tree | 4ad6c2afa957672984edeb0a09d74d60564bbab3 /usr.sbin | |
parent | 9fffe2524dd695053a4ad0b6fa7428f3023b33e6 (diff) | |
download | FreeBSD-src-a9bfaebd85834b2174fc8556e888c5dc381ace2f.zip FreeBSD-src-a9bfaebd85834b2174fc8556e888c5dc381ace2f.tar.gz |
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.
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/rpcbind/rpcb_svc_com.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/usr.sbin/rpcbind/rpcb_svc_com.c b/usr.sbin/rpcbind/rpcb_svc_com.c index 326224a..2ee2a4c 100644 --- a/usr.sbin/rpcbind/rpcb_svc_com.c +++ b/usr.sbin/rpcbind/rpcb_svc_com.c @@ -1051,17 +1051,19 @@ netbufcmp(struct netbuf *n1, struct netbuf *n2) 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); } |