Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 12 Jul 2005 18:34:09 +0200 (CEST)
From:      Dan Lukes <dan@obluda.cz>
To:        FreeBSD-gnats-submit@FreeBSD.org
Subject:   bin/83338: [ PATCH ] libc's getent() don't check for malloc failure
Message-ID:  <200507121634.j6CGY9BP015766@kulesh.obluda.cz>
Resent-Message-ID: <200507121640.j6CGeBu6055985@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>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:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200507121634.j6CGY9BP015766>