bin/83348: [ PATCH ] Improper handling of malloc failures within libc's yp/xdryp.c

Dan Lukes dan at obluda.cz
Tue Jul 12 19:50:21 GMT 2005


>Number:         83348
>Category:       bin
>Synopsis:       [ PATCH ] Improper handling of malloc failures within libc's yp/xdryp.c
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Jul 12 19:50:19 GMT 2005
>Closed-Date:
>Last-Modified:
>Originator:     Dan Lukes
>Release:        FreeBSD 5.4-STABLE i386
>Organization:
Obludarium
>Environment:
System: FreeBSD 5.4-STABLE #8: Sat Jul 9 16:31:08 CEST 2005 i386
lib/libc/yp/xdryp.c,v 1.14 2002/04/28 15:18:47 des

	
>Description:
	Improper handling of malloc failures
>How-To-Repeat:
>Fix:

--- patch begins here ---
--- lib/libc/yp/xdryp.c.ORIG	Sun Apr 28 17:18:47 2002
+++ lib/libc/yp/xdryp.c	Tue Jul 12 21:37:07 2005
@@ -82,10 +82,21 @@
 		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';
--- patch ends here ---
>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-bugs mailing list