[PATCH 2/2] rxrpc: use kmemdup_nul in rxrpc_krb5_decode_principal

From: Rasmus Villemoes
Date: Fri Sep 07 2018 - 03:46:50 EST


Signed-off-by: Rasmus Villemoes <linux@xxxxxxxxxxxxxxxxxx>
---
This depends on patch 1/2.

net/rxrpc/key.c | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/net/rxrpc/key.c b/net/rxrpc/key.c
index e7f6b8823eb6..42f0ca9265c2 100644
--- a/net/rxrpc/key.c
+++ b/net/rxrpc/key.c
@@ -252,11 +252,9 @@ static int rxrpc_krb5_decode_principal(struct krb5_principal *princ,
paddedlen = (tmp + 3) & ~3;
if (paddedlen > toklen)
return -EINVAL;
- princ->name_parts[loop] = kmalloc(tmp + 1, GFP_KERNEL);
+ princ->name_parts[loop] = kmemdup_nul(xdr, tmp, GFP_KERNEL);
if (!princ->name_parts[loop])
return -ENOMEM;
- memcpy(princ->name_parts[loop], xdr, tmp);
- princ->name_parts[loop][tmp] = 0;
toklen -= paddedlen;
xdr += paddedlen >> 2;
}
@@ -270,11 +268,9 @@ static int rxrpc_krb5_decode_principal(struct krb5_principal *princ,
paddedlen = (tmp + 3) & ~3;
if (paddedlen > toklen)
return -EINVAL;
- princ->realm = kmalloc(tmp + 1, GFP_KERNEL);
+ princ->realm = kmemdup_nul(xdr, tmp, GFP_KERNEL);
if (!princ->realm)
return -ENOMEM;
- memcpy(princ->realm, xdr, tmp);
- princ->realm[tmp] = 0;
toklen -= paddedlen;
xdr += paddedlen >> 2;

--
2.16.4