@@ -1085,13 +1085,10 @@ nfs4_decode_mp_ds_addr(struct net *net, struct xdr_stream *xdr, gfp_t gfp_flags)
if (unlikely(!p))
goto out_err;
- netid = kmalloc(nlen+1, gfp_flags);
+ netid = kmemdup_nul(p, nlen, gfp_flags);
if (unlikely(!netid))
goto out_err;
- netid[nlen] = '\0';
- memcpy(netid, p, nlen);
-
/* r_addr: ip/ip6addr with port in dec octets - see RFC 5665 */
p = xdr_inline_decode(xdr, 4);
if (unlikely(!p))
@@ -1108,13 +1105,11 @@ nfs4_decode_mp_ds_addr(struct net *net, struct xdr_stream *xdr, gfp_t gfp_flags)
rlen);
goto out_free_netid;
}
- buf = kmalloc(rlen + 1, gfp_flags);
+ buf = kmemdup_nul(p, rlen, gfp_flags);
if (!buf) {
dprintk("%s: Not enough memory\n", __func__);
goto out_free_netid;
}
- buf[rlen] = '\0';
- memcpy(buf, p, rlen);
/* replace port '.' with '-' */
portstr = strrchr(buf, '.');