From dan@kulesh.obluda.cz  Tue Jul 12 16:07:09 2005
Return-Path: <dan@kulesh.obluda.cz>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id D1C6316A41C
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 12 Jul 2005 16:07:09 +0000 (GMT)
	(envelope-from dan@kulesh.obluda.cz)
Received: from kulesh.obluda.cz (kulesh.obluda.cz [193.179.22.243])
	by mx1.FreeBSD.org (Postfix) with ESMTP id A402943D5C
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 12 Jul 2005 16:07:08 +0000 (GMT)
	(envelope-from dan@kulesh.obluda.cz)
Received: from kulesh.obluda.cz (localhost.eunet.cz [127.0.0.1])
	by kulesh.obluda.cz (8.13.3/8.13.3) with ESMTP id j6CG6tUG015601
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 12 Jul 2005 18:06:56 +0200 (CEST)
	(envelope-from dan@kulesh.obluda.cz)
Received: (from root@localhost)
	by kulesh.obluda.cz (8.13.3/8.13.1/Submit) id j6CG6ooF015600;
	Tue, 12 Jul 2005 18:06:50 +0200 (CEST)
	(envelope-from dan)
Message-Id: <200507121606.j6CG6ooF015600@kulesh.obluda.cz>
Date: Tue, 12 Jul 2005 18:06:50 +0200 (CEST)
From: Dan Lukes <dan@obluda.cz>
Reply-To: Dan Lukes <dan@obluda.cz>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [ PATCH ] libc's parse_ncp() don't check malloc/realloc for failures
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         83336
>Category:       bin
>Synopsis:       [patch] libc's parse_ncp() don't check malloc/realloc for failures
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    delphij
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Jul 12 16:10:25 GMT 2005
>Closed-Date:    Thu Apr 02 21:59:57 UTC 2009
>Last-Modified:  Thu Apr 02 21:59:57 UTC 2009
>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/rpc/getnetconfig.c,v 1.10 2004/03/05 08:10:17 markm

>Description:
	parse_ncp() called from getnetconfig() and getnetconfigent() dodn't
check malloc/realloc for failures. It may cause NULL dereferencing.

	It assume the allocated memory is '\0' filled also.

>How-To-Repeat:
>Fix:

--- patch begins here ---
--- lib/libc/rpc/getnetconfig.c.ORIG	Mon Mar  8 14:41:03 2004
+++ lib/libc/rpc/getnetconfig.c	Tue Jul 12 17:43:19 2005
@@ -420,18 +420,6 @@
 	return (NULL);
     }
 
-    if (strcmp(netid, "unix") == 0) {
-	fprintf(stderr, "The local transport is called \"unix\" ");
-	fprintf(stderr, "in /etc/netconfig.\n");
-	fprintf(stderr, "Please change this to \"local\" manually ");
-	fprintf(stderr, "or run mergemaster(8).\n");
-	fprintf(stderr, "See UPDATING entry 20021216 for details.\n");
-	fprintf(stderr, "Continuing in 10 seconds\n\n");
-	fprintf(stderr, "This warning will be removed 20030301\n");
-	sleep(10);
-
-    }
-
     /*
      * Look up table if the entries have already been read and parsed in
      * getnetconfig(), then copy this entry into a buffer and return it.
@@ -603,13 +591,18 @@
 	    free(ncp->nc_lookups);
 	/* preallocate one string pointer */
 	ncp->nc_lookups = (char **)malloc(sizeof (char *));
+	if (ncp->nc_lookups == NULL)
+	    return(-1);
 	ncp->nc_nlookups = 0;
 	while ((cp = tokenp) != NULL) {
 	    tokenp = _get_next_token(cp, ',');
 	    ncp->nc_lookups[(size_t)ncp->nc_nlookups++] = cp;
-	    ncp->nc_lookups = (char **)realloc(ncp->nc_lookups,
+	    ncp->nc_lookups = (char **)reallocf(ncp->nc_lookups,
 		(size_t)(ncp->nc_nlookups+1) *sizeof(char *));	/* for next loop */
+	    if (ncp->nc_lookups == NULL)
+		return(-1);
 	}
+	ncp->nc_lookups[(size_t)ncp->nc_nlookups] = '\0';
     }
     return (0);
 }
--- patch ends here ---
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: delphij 
State-Changed-When: Thu Apr 2 21:58:53 UTC 2009 
State-Changed-Why:  
The reported bug has been fixed on 2007-09-20 on -HEAD and 
is now merged to all supported branches, thanks for your 
submission! 


Responsible-Changed-From-To: freebsd-bugs->delphij 
Responsible-Changed-By: delphij 
Responsible-Changed-When: Thu Apr 2 21:58:53 UTC 2009 
Responsible-Changed-Why:  
Take. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=83336 
>Unformatted:
