From 53fc6e1e4d71b756eb75744531530e8a08f6a66f Mon Sep 17 00:00:00 2001 From: Guy Helmer Date: Fri, 23 Dec 2011 01:56:25 +0000 Subject: [PATCH] Handle failures to malloc memory to hold key or val copies. PR: bin/83348 --- lib/libc/yp/xdryp.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/libc/yp/xdryp.c b/lib/libc/yp/xdryp.c index ec2f71a1a2a..bb9096bb289 100644 --- a/lib/libc/yp/xdryp.c +++ b/lib/libc/yp/xdryp.c @@ -82,10 +82,21 @@ xdr_ypresp_all_seq(XDR *xdrs, u_long *objp) switch (status) { case YP_TRUE: key = (char *)malloc(out.ypresp_all_u.val.key.keydat_len + 1); + if (key == NULL) { + xdr_free((xdrproc_t)xdr_ypresp_all, &out); + *objp = YP_YPERR; + return (FALSE); + } bcopy(out.ypresp_all_u.val.key.keydat_val, key, out.ypresp_all_u.val.key.keydat_len); key[out.ypresp_all_u.val.key.keydat_len] = '\0'; val = (char *)malloc(out.ypresp_all_u.val.val.valdat_len + 1); + if (val == NULL) { + free(key); + xdr_free((xdrproc_t)xdr_ypresp_all, &out); + *objp = YP_YPERR; + return (FALSE); + } bcopy(out.ypresp_all_u.val.val.valdat_val, val, out.ypresp_all_u.val.val.valdat_len); val[out.ypresp_all_u.val.val.valdat_len] = '\0';