Date: Wed, 13 Jul 2005 09:13:41 +0200 (CEST) From: Dan Lukes <dan@obluda.cz> To: FreeBSD-gnats-submit@FreeBSD.org Subject: bin/83368: [ PATCH ] incorrect handling of malloc failures within libncp's ncp_open_rcfile() Message-ID: <200507130713.j6D7DfW7022526@kulesh.obluda.cz> Resent-Message-ID: <200507130720.j6D7KJqT096535@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>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 <stdlib.h> #include <pwd.h> #include <unistd.h> +#include <err.h> #include <netncp/ncp_lib.h> #include <netncp/ncp_rcfile.h> @@ -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 <stdio.h> #include <fcntl.h> #include <unistd.h> -#include <strings.h> +#include <string.h> #include <netncp/ncp_lib.h> #include <netncp/ncp_file.h> --- 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 <arpa/inet.h> #include <errno.h> #include <stdio.h> -#include <strings.h> +#include <string.h> #include <netncp/ncp_lib.h> --- 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 <sys/types.h> #include <errno.h> #include <stdio.h> -#include <strings.h> +#include <string.h> #include <netncp/ncp_lib.h> #include <netncp/ncp_nls.h> --- 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 <ctype.h> #include <errno.h> #include <stdio.h> -#include <strings.h> +#include <string.h> #include <locale.h> #include <netncp/ncp_lib.h> --- 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 <sys/types.h> #include <errno.h> #include <stdio.h> +#include <string.h> #include <netncp/ncp_lib.h> 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 <arpa/inet.h> #include <errno.h> #include <stdio.h> -#include <strings.h> +#include <string.h> #include <netncp/ncp_lib.h> 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 <bsd.lib.mk> --- 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?200507130713.j6D7DfW7022526>