From owner-freebsd-bugs@FreeBSD.ORG Wed Jul 13 07:20:20 2005 Return-Path: X-Original-To: freebsd-bugs@hub.freebsd.org Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id A260C16A41C for ; Wed, 13 Jul 2005 07:20:20 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 227B943D48 for ; Wed, 13 Jul 2005 07:20:20 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.3/8.13.3) with ESMTP id j6D7KJtK096539 for ; Wed, 13 Jul 2005 07:20:19 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.3/8.13.1/Submit) id j6D7KJqT096535; Wed, 13 Jul 2005 07:20:19 GMT (envelope-from gnats) Resent-Date: Wed, 13 Jul 2005 07:20:19 GMT Resent-Message-Id: <200507130720.j6D7KJqT096535@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Dan Lukes Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id D9E9E16A41C for ; Wed, 13 Jul 2005 07:13:45 +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 58D6A43D45 for ; Wed, 13 Jul 2005 07:13:44 +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 j6D7Dfku022527 for ; Wed, 13 Jul 2005 09:13:42 +0200 (CEST) (envelope-from dan@kulesh.obluda.cz) Received: (from root@localhost) by kulesh.obluda.cz (8.13.3/8.13.1/Submit) id j6D7DfW7022526; Wed, 13 Jul 2005 09:13:41 +0200 (CEST) (envelope-from dan) Message-Id: <200507130713.j6D7DfW7022526@kulesh.obluda.cz> Date: Wed, 13 Jul 2005 09:13:41 +0200 (CEST) From: Dan Lukes To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Cc: Subject: bin/83368: [ PATCH ] incorrect handling of malloc failures within libncp's ncp_open_rcfile() X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Dan Lukes List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 Jul 2005 07:20:20 -0000 >Number: 83368 >Category: bin >Synopsis: [ PATCH ] incorrect handling of malloc failures within libncp's ncp_open_rcfile() >Confidential: no >Severity: serious >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Wed Jul 13 07:20: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/libncp/ncpl_rcfile.c,v 1.4 2001/09/30 22:01:19 dillon lib/libncp/ncpl_file.c,v 1.5 2002/02/18 20:35:18 mike lib/libncp/ncpl_misc.c,v 1.5 2002/02/18 20:35:18 mike lib/libncp/ncpl_msg.c,v 1.2 2001/09/30 22:01:19 dillon lib/libncp/ncpl_nls.c,v 1.5 2004/03/14 05:19:38 bde lib/libncp/ncpl_queue.c,v 1.3 2001/09/30 22:01:19 dillon lib/libncp/ncpl_rpc.c,v 1.3 2002/02/18 20:35:18 mike lib/libncp/ncpl_subr.c,v 1.10 2004/06/02 03:41:10 bp lib/libncp/Makefile,v 1.4 2002/09/28 00:25:30 peter >Description: Major problem is incorrect handling of malloc failures within ncpl_rcfile.c:ncp_open_rcfile() Minor problem is include of strings.h which isn't necesary instead of string.h which is needed for declaration of memcpy() within most of libncp's sources >How-To-Repeat: >Fix: --- patch begins here --- --- lib/libncp/ncpl_rcfile.c.ORIG Mon Jul 1 22:53:31 2002 +++ lib/libncp/ncpl_rcfile.c Wed Jul 13 08:48:50 2005 @@ -42,6 +42,7 @@ #include #include #include +#include #include #include @@ -393,15 +394,18 @@ int error; home = getenv("HOME"); - if (home) { - fn = malloc(strlen(home) + 20); + if ( home != NULL) { + if ((fn = malloc(strlen(home) + 20)) == NULL) { + warn("Cannot read %s/.nwfsrc", home); + return(ENOMEM); + } sprintf(fn, "%s/.nwfsrc", home); error = rc_open(fn,"r",&ncp_rc); free (fn); } error = rc_merge(NWFS_CFG_FILE, &ncp_rc); if( ncp_rc == NULL ) { - printf("Warning: no cfg files found.\n"); + warnx("Warning: no cfg files found."); return 1; } return 0; --- lib/libncp/ncpl_file.c.ORIG Mon Jul 1 22:53:30 2002 +++ lib/libncp/ncpl_file.c Wed Jul 13 08:53:49 2005 @@ -40,7 +40,7 @@ #include #include #include -#include +#include #include #include --- lib/libncp/ncpl_misc.c.ORIG Mon Jul 1 22:53:30 2002 +++ lib/libncp/ncpl_misc.c Wed Jul 13 08:53:41 2005 @@ -40,7 +40,7 @@ #include #include #include -#include +#include #include --- lib/libncp/ncpl_msg.c.ORIG Mon Jul 1 22:53:30 2002 +++ lib/libncp/ncpl_msg.c Wed Jul 13 08:52:22 2005 @@ -36,7 +36,7 @@ #include #include #include -#include +#include #include #include --- lib/libncp/ncpl_nls.c.ORIG Wed Mar 17 01:03:35 2004 +++ lib/libncp/ncpl_nls.c Wed Jul 13 08:52:29 2005 @@ -40,7 +40,7 @@ #include #include #include -#include +#include #include #include --- lib/libncp/ncpl_queue.c.ORIG Mon Jul 1 22:53:31 2002 +++ lib/libncp/ncpl_queue.c Wed Jul 13 08:55:56 2005 @@ -38,6 +38,7 @@ #include #include #include +#include #include int --- lib/libncp/ncpl_rpc.c.ORIG Mon Jul 1 22:53:31 2002 +++ lib/libncp/ncpl_rpc.c Wed Jul 13 08:50:38 2005 @@ -39,7 +39,7 @@ #include #include #include -#include +#include #include struct ncp_rpc_rq { --- lib/libncp/ncpl_subr.c.ORIG Wed Jun 16 12:48:40 2004 +++ lib/libncp/ncpl_subr.c Wed Jul 13 08:57:48 2005 @@ -329,7 +329,7 @@ ++ncp_optind; if (ncp_opterr && *ostr != ':') (void)fprintf(stderr, - "%s: illegal option -- %c\n", _getprogname(), ncp_optopt); + "%s: illegal option -- %c\n", getprogname(), ncp_optopt); return (BADCH); } if (*++oli != ':') { /* don't need argument */ @@ -347,7 +347,7 @@ if (ncp_opterr) (void)fprintf(stderr, "%s: option requires an argument -- %c\n", - _getprogname(), ncp_optopt); + getprogname(), ncp_optopt); return (BADCH); } else /* white space */ @@ -459,7 +459,7 @@ ncp_error(const char *fmt, int error, ...) { va_list ap; - fprintf(stderr, "%s: ", _getprogname()); + fprintf(stderr, "%s: ", getprogname()); va_start(ap, error); vfprintf(stderr, fmt, ap); va_end(ap); --- lib/libncp/Makefile.ORIG Sun Sep 29 03:09:32 2002 +++ lib/libncp/Makefile Wed Jul 13 08:46:15 2005 @@ -12,4 +12,6 @@ ncpl_net.c ncpl_rcfile.c ncpl_conn.c ncpl_nls.c ncpl_msg.c \ ncpl_rpc.c ncpl_crypt.c ipx.c sap.c +WARNS+= 2 + .include --- patch ends here --- >Release-Note: >Audit-Trail: >Unformatted: