changeset 2934:5745c107c2e3

6478243 ippool can dump core (Regression) 6480720 ipnat usage output incorrect (Regression) 6480905 some ipfilter tools once again don't check for return values from memory allocation (Regression)
author jojemann
date Tue, 17 Oct 2006 05:42:55 -0700
parents b83c1115488b
children 52335ad0c6ce
files usr/src/cmd/ipf/tools/ipfcomp.c usr/src/cmd/ipf/tools/ipnat.c usr/src/cmd/ipf/tools/ippool.c
diffstat 3 files changed, 36 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/usr/src/cmd/ipf/tools/ipfcomp.c	Tue Oct 17 00:27:18 2006 -0700
+++ b/usr/src/cmd/ipf/tools/ipfcomp.c	Tue Oct 17 05:42:55 2006 -0700
@@ -2,7 +2,13 @@
  * Copyright (C) 1993-2001 by Darren Reed.
  *
  * See the IPFILTER.LICENCE file for details on licencing.
+ *
+ * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
  */
+
+#pragma ident	"%Z%%M%	%I%	%E% SMI"
+
 #if !defined(lint)
 static const char sccsid[] = "@(#)ip_fil.c	2.41 6/5/96 (C) 1993-2000 Darren Reed";
 static const char rcsid[] = "@(#)$Id: ipfcomp.c,v 1.24.2.2 2004/04/28 10:34:44 darrenr Exp $";
@@ -159,9 +165,17 @@
 	int i;
 
 	f = (frentry_t *)malloc(sizeof(*f));
+	if (f == NULL) {
+		fprintf(stderr, "out of memory\n");
+		exit(1);
+	}
 	bcopy((char *)fr, (char *)f, sizeof(*fr));
 	if (fr->fr_ipf) {
 		f->fr_ipf = (fripf_t *)malloc(sizeof(*f->fr_ipf));
+		if (f->fr_ipf == NULL) {
+			fprintf(stderr, "out of memory\n");
+			exit(1);
+		}
 		bcopy((char *)fr->fr_ipf, (char *)f->fr_ipf,
 		      sizeof(*fr->fr_ipf));
 	}
@@ -174,6 +188,10 @@
 
 	if (g == NULL) {
 		g = (frgroup_t *)calloc(1, sizeof(*g));
+		if (g == NULL) {
+			fprintf(stderr, "out of memory\n");
+			exit(1);
+		}
 		g->fg_next = groups;
 		groups = g;
 		g->fg_head = f;
@@ -214,6 +232,10 @@
 				break;
 		if (g == NULL) {
 			g = (frgroup_t *)calloc(1, sizeof(*g));
+			if (g == NULL) {
+				fprintf(stderr, "out of memory\n");
+				exit(1);
+			}
 			g->fg_next = groups;
 			groups = g;
 			g->fg_head = f;
@@ -931,8 +953,13 @@
 			fr->fr_flags & FR_INQUE ? "in" : "out",
 			fr->fr_group, num);
 	}
-	if (n == NULL)
+	if (n == NULL) { 
 		n = (mc_t *)malloc(sizeof(*n) * FRC_MAX);
+		if (n == NULL) {
+			fprintf(stderr, "out of memory\n");
+			exit(1);
+		}
+	}
 	bcopy((char *)m, (char *)n, sizeof(*n) * FRC_MAX);
 	sin = in;
 }
@@ -944,8 +971,13 @@
 	static mc_t *m = NULL;
 	frgroup_t *g;
 
-	if (m == NULL)
+	if (m == NULL) { 
 		m = (mc_t *)calloc(1, sizeof(*m) * FRC_MAX);
+		if (m == NULL) { 
+			fprintf(stderr, "out of memory\n"); 
+			exit(1); 
+		} 
+	} 
 
 	for (g = groups; g != NULL; g = g->fg_next) {
 		if ((dir == 0) && ((g->fg_flags & FR_INQUE) != 0))
--- a/usr/src/cmd/ipf/tools/ipnat.c	Tue Oct 17 00:27:18 2006 -0700
+++ b/usr/src/cmd/ipf/tools/ipnat.c	Tue Oct 17 05:42:55 2006 -0700
@@ -94,7 +94,7 @@
 void usage(name)
 char *name;
 {
-	fprintf(stderr, "Usage: %s [-CFhlnrRsv] [-f filename]\n", name);
+	fprintf(stderr, "Usage: %s [-CdFhlnrRsv] [-f filename]\n", name);
 	exit(1);
 }
 
--- a/usr/src/cmd/ipf/tools/ippool.c	Tue Oct 17 00:27:18 2006 -0700
+++ b/usr/src/cmd/ipf/tools/ippool.c	Tue Oct 17 05:42:55 2006 -0700
@@ -215,7 +215,7 @@
 	bzero((char *)&iph, sizeof(iph));
 	bzero((char *)&pool, sizeof(pool));
 
-	while ((c = getopt(argc, argv, "dm:no:RSt:v")) != -1)
+	while ((c = getopt(argc, argv, "dm:no:RS:t:v")) != -1)
 		switch (c)
 		{
 		case 'd' :