bin/83338: [ PATCH ] libc's getent() don't check for malloc failure

Dan Lukes dan at obluda.cz
Tue Jul 12 16:40:11 GMT 2005


>Number:         83338
>Category:       bin
>Synopsis:       [ PATCH ] libc's getent() don't check for malloc failure
>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 16:40:10 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
src/lib/libc/gen/getcap.c,v 1.19 2003/01/02 10:19:43 thomas

>Description:
	getent() called from cgetent() don't check for malloc failure
>How-To-Repeat:
>Fix:

--- patch begins here ---
--- lib/libc/gen/getcap.c.ORIG	Thu Jan  2 20:26:24 2003
+++ lib/libc/gen/getcap.c	Tue Jul 12 18:27:20 2005
@@ -255,9 +255,11 @@
 					return (retval);
 				}
 				/* save the data; close frees it */
-				clen = strlen(record);
-				cbuf = malloc(clen + 1);
-				memcpy(cbuf, record, clen + 1);
+				if ((clen = strdup(record)) == NULL) {
+					capdbp->close(capdbp);
+					errno = ENOMEM;
+					return (-2);
+				}
 				if (capdbp->close(capdbp) < 0) {
 					free(cbuf);
 					return (-2);
--- patch ends here ---
>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-bugs mailing list