579c9b0
diff -up net-tools-1.60/ipmaddr.c.coverity net-tools-1.60/ipmaddr.c
579c9b0
--- net-tools-1.60/ipmaddr.c.coverity	2001-04-08 19:04:23.000000000 +0200
579c9b0
+++ net-tools-1.60/ipmaddr.c	2011-04-28 16:35:24.000000000 +0200
579c9b0
@@ -160,7 +160,11 @@ void read_dev_mcast(struct ma_info **res
579c9b0
 		len = parse_hex(hexa, (unsigned char*)&m.addr.data);
579c9b0
 		if (len >= 0) {
579c9b0
 			struct ma_info *ma = malloc(sizeof(m));
579c9b0
-
579c9b0
+			if (!ma) {
579c9b0
+				fprintf(stderr, "couldn't allocate memory\n");
579c9b0
+				fclose(fp);
579c9b0
+				return;
579c9b0
+			}
579c9b0
 			memcpy(ma, &m, sizeof(m));
579c9b0
 			ma->addr.bytelen = len;
579c9b0
 			ma->addr.bitlen = len<<3;
579c9b0
@@ -174,7 +178,7 @@ void read_dev_mcast(struct ma_info **res
579c9b0
 
579c9b0
 void read_igmp(struct ma_info **result_p)
579c9b0
 {
579c9b0
-	struct ma_info m;
579c9b0
+	struct ma_info m, *ma = NULL;
579c9b0
 	char buf[256];
579c9b0
 	FILE *fp = fopen(_PATH_PROCNET_IGMP, "r");
579c9b0
 
579c9b0
@@ -188,8 +192,6 @@ void read_igmp(struct ma_info **result_p
579c9b0
 	m.addr.bytelen = 4;
579c9b0
 
579c9b0
 	while (fgets(buf, sizeof(buf), fp)) {
579c9b0
-		struct ma_info *ma = malloc(sizeof(m));
579c9b0
-
579c9b0
 		if (buf[0] != '\t') {
579c9b0
 			sscanf(buf, "%d%s", &m.index, m.name);
579c9b0
 			continue;
579c9b0
@@ -201,6 +203,12 @@ void read_igmp(struct ma_info **result_p
579c9b0
 		sscanf(buf, "%08x%d", (__u32*)&m.addr.data, &m.users);
579c9b0
 
579c9b0
 		ma = malloc(sizeof(m));
579c9b0
+		if (!ma) {
579c9b0
+			fprintf(stderr, "couldn't allocate memory\n");
579c9b0
+			fclose(fp);
579c9b0
+			return;
579c9b0
+		}
579c9b0
+
579c9b0
 		memcpy(ma, &m, sizeof(m));
579c9b0
 		maddr_ins(result_p, ma);
579c9b0
 	}
579c9b0
@@ -232,6 +240,11 @@ void read_igmp6(struct ma_info **result_
579c9b0
 		len = parse_hex(hexa, (unsigned char*)&m.addr.data);
579c9b0
 		if (len >= 0) {
579c9b0
 			struct ma_info *ma = malloc(sizeof(m));
579c9b0
+			if (!ma) {
579c9b0
+				fprintf(stderr, "couldn't allocate memory\n");
579c9b0
+				fclose(fp);
579c9b0
+				return;
579c9b0
+			}
579c9b0
 
579c9b0
 			memcpy(ma, &m, sizeof(m));
579c9b0
 
579c9b0
diff -up net-tools-1.60/iptunnel.c.coverity net-tools-1.60/iptunnel.c
579c9b0
--- net-tools-1.60/iptunnel.c.coverity	2001-04-08 19:04:23.000000000 +0200
579c9b0
+++ net-tools-1.60/iptunnel.c	2011-04-28 15:26:06.000000000 +0200
579c9b0
@@ -485,6 +485,7 @@ static int do_tunnels_list(struct ip_tun
579c9b0
 		if ((ptr = strchr(buf, ':')) == NULL ||
579c9b0
 		    (*ptr++ = 0, sscanf(buf, "%s", name) != 1)) {
579c9b0
 			fprintf(stderr, _("Wrong format of /proc/net/dev. Sorry.\n"));
579c9b0
+			fclose(fp);
579c9b0
 			return -1;
579c9b0
 		}
579c9b0
 		if (sscanf(ptr, "%ld%ld%ld%ld%ld%ld%ld%*d%ld%ld%ld%ld%ld%ld%ld",
579c9b0
@@ -521,6 +522,7 @@ static int do_tunnels_list(struct ip_tun
579c9b0
 			       tx_packets, tx_bytes, tx_errs, tx_colls, tx_carrier, tx_drops);
579c9b0
 		}
579c9b0
 	}
579c9b0
+	fclose(fp);
579c9b0
 	return 0;
579c9b0
 }
579c9b0
 
579c9b0
diff -up net-tools-1.60/lib/inet.c.coverity net-tools-1.60/lib/inet.c
579c9b0
--- net-tools-1.60/lib/inet.c.coverity	2000-05-22 23:27:13.000000000 +0200
579c9b0
+++ net-tools-1.60/lib/inet.c	2011-04-28 14:39:06.000000000 +0200
579c9b0
@@ -211,10 +211,18 @@ static int INET_rresolve(char *name, siz
579c9b0
     if ((ent == NULL) && (np == NULL))
579c9b0
 	safe_strncpy(name, inet_ntoa(sin->sin_addr), len);
579c9b0
     pn = (struct addr *) malloc(sizeof(struct addr));
579c9b0
+    if (!pn) {
579c9b0
+        fprintf (stderr, "rresolve: couldn't allocate memory\n");
579c9b0
+        return (0);
579c9b0
+    }
579c9b0
     pn->addr = *sin;
579c9b0
     pn->next = INET_nn;
579c9b0
     pn->host = host;
579c9b0
     pn->name = (char *) malloc(strlen(name) + 1);
579c9b0
+    if (!pn->name) {
579c9b0
+        fprintf (stderr, "rresolve: couldn't allocate memory\n");
579c9b0
+        return (0);
579c9b0
+    }
579c9b0
     strcpy(pn->name, name);
579c9b0
     INET_nn = pn;
579c9b0
 
579c9b0
@@ -386,8 +394,11 @@ static int read_services(void)
579c9b0
     while ((se = getservent())) {
579c9b0
 	/* Allocate a service entry. */
579c9b0
 	item = (struct service *) malloc(sizeof(struct service));
579c9b0
-	if (item == NULL)
579c9b0
-	    perror("netstat");
579c9b0
+	if (item == NULL) {
579c9b0
+	    perror("netstat: couldn't allocate memory");
579c9b0
+	    endservent();
579c9b0
+	    return (0);
579c9b0
+	}
579c9b0
 	item->name = strdup(se->s_name);
579c9b0
 	item->number = se->s_port;
579c9b0
 
579c9b0
@@ -405,8 +416,11 @@ static int read_services(void)
579c9b0
     while ((pe = getprotoent())) {
579c9b0
 	/* Allocate a service entry. */
579c9b0
 	item = (struct service *) malloc(sizeof(struct service));
579c9b0
-	if (item == NULL)
579c9b0
-	    perror("netstat");
579c9b0
+	if (item == NULL) {
579c9b0
+	    perror("netstat: couldn't allocate memory");
579c9b0
+	    endprotoent();
579c9b0
+	    return (0);
579c9b0
+	}
579c9b0
 	item->name = strdup(pe->p_name);
579c9b0
 	item->number = htons(pe->p_proto);
579c9b0
 	add2list(&raw_name, item);
579c9b0
diff -up net-tools-1.60/lib/ipx_gr.c.coverity net-tools-1.60/lib/ipx_gr.c
579c9b0
--- net-tools-1.60/lib/ipx_gr.c.coverity	2011-04-21 14:00:20.000000000 +0200
579c9b0
+++ net-tools-1.60/lib/ipx_gr.c	2011-04-28 14:16:49.000000000 +0200
579c9b0
@@ -38,7 +38,7 @@ int IPX_rprint(int options)
579c9b0
     char net[128], router_net[128];
579c9b0
     char router_node[128];
579c9b0
     int num;
579c9b0
-    FILE *fp = fopen(_PATH_PROCNET_IPX_ROUTE, "r");
579c9b0
+    FILE *fp = NULL;
579c9b0
     struct aftype *ap;
579c9b0
     struct sockaddr sa;
579c9b0
 
579c9b0
@@ -47,6 +47,7 @@ int IPX_rprint(int options)
579c9b0
 	return (-1);
579c9b0
     }
579c9b0
 
579c9b0
+    fp = fopen(_PATH_PROCNET_IPX_ROUTE, "r");
579c9b0
     if (!fp) {
579c9b0
         perror(_PATH_PROCNET_IPX_ROUTE);
579c9b0
         printf(_("IPX not configured in this system.\n"));
579c9b0
diff -up net-tools-1.60/lib/masq_info.c.coverity net-tools-1.60/lib/masq_info.c
579c9b0
--- net-tools-1.60/lib/masq_info.c.coverity	2011-04-21 14:00:20.000000000 +0200
579c9b0
+++ net-tools-1.60/lib/masq_info.c	2011-04-28 15:34:06.000000000 +0200
579c9b0
@@ -208,10 +208,9 @@ int ip_masq_info(int numeric_host, int n
579c9b0
 	}
579c9b0
 	for (i = 0; i < ntotal; i++)
579c9b0
 	    print_masq(&(mslist[i]), numeric_host, numeric_port, ext);
579c9b0
-	if (mslist)
579c9b0
-	    free(mslist);
579c9b0
-
579c9b0
     }
579c9b0
+    if (mslist)
579c9b0
+        free(mslist);
579c9b0
     return 0;
579c9b0
 }
579c9b0
 #endif
579c9b0
diff -up net-tools-1.60/lib/netrom_gr.c.coverity net-tools-1.60/lib/netrom_gr.c
579c9b0
--- net-tools-1.60/lib/netrom_gr.c.coverity	2000-10-28 12:59:42.000000000 +0200
579c9b0
+++ net-tools-1.60/lib/netrom_gr.c	2011-04-28 14:15:38.000000000 +0200
579c9b0
@@ -39,9 +39,7 @@ int NETROM_rprint(int options)
579c9b0
     /*int ext = options & FLAG_EXT;
579c9b0
        int numeric = options & FLAG_NUM_HOST; */
579c9b0
 
579c9b0
-    f1 = fopen(_PATH_PROCNET_NR_NODES, "r");
579c9b0
     if (!f1) perror(_PATH_PROCNET_NR_NODES);
579c9b0
-    f2 = fopen(_PATH_PROCNET_NR_NEIGH, "r");
579c9b0
     if (!f2) perror(_PATH_PROCNET_NR_NEIGH);
579c9b0
 
579c9b0
     if (f1 == NULL || f2 == NULL) {
579c9b0
diff -up net-tools-1.60/lib/x25.c.coverity net-tools-1.60/lib/x25.c
579c9b0
--- net-tools-1.60/lib/x25.c.coverity	2011-04-21 14:00:20.000000000 +0200
579c9b0
+++ net-tools-1.60/lib/x25.c	2011-04-28 15:01:47.000000000 +0200
579c9b0
@@ -106,7 +106,8 @@ X25_input(int type, char *bufp, struct s
579c9b0
   }
579c9b0
 
579c9b0
   if (strlen(bufp) < 1 || strlen(bufp) > 15 || sigdigits > strlen(bufp)) {
579c9b0
-	*p = '/';
579c9b0
+        if (p != NULL)
579c9b0
+                *p = '/';
579c9b0
         strcpy(X25_errmsg, _("Invalid address"));
579c9b0
 #ifdef DEBUG
579c9b0
         fprintf(stderr, "x25_input(%s): %s !\n", bufp, X25_errmsg);
579c9b0
diff -up net-tools-1.60/nameif.c.coverity net-tools-1.60/nameif.c
579c9b0
--- net-tools-1.60/nameif.c.coverity	2011-04-21 14:00:20.000000000 +0200
579c9b0
+++ net-tools-1.60/nameif.c	2011-04-28 15:55:20.000000000 +0200
579c9b0
@@ -154,6 +154,7 @@ void readconf(void)
579c9b0
 	FILE *ifh;
579c9b0
 	char *p;
579c9b0
 	int n;
579c9b0
+	struct change *ch = NULL;
579c9b0
 
579c9b0
 	ifh = fopen(fname, "r");
579c9b0
 	if (!ifh) 
579c9b0
@@ -163,7 +164,7 @@ void readconf(void)
579c9b0
 	linel = 0;
579c9b0
 	linenum = 1; 
579c9b0
 	while (getdelim(&line, &linel, '\n', ifh) > 0) {
579c9b0
-		struct change *ch = xmalloc(sizeof(struct change)); 
579c9b0
+
579c9b0
 		char pos[20]; 
579c9b0
 
579c9b0
 		sprintf(pos, _("line %d"), linenum); 
579c9b0
@@ -178,6 +179,11 @@ void readconf(void)
579c9b0
 		n = strcspn(p, " \t"); 
579c9b0
 		if (n > IFNAMSIZ) 
579c9b0
 			complain(_("interface name too long at line %d"), line);  
579c9b0
+		ch = xmalloc(sizeof(struct change));
579c9b0
+		if (!ch) {
579c9b0
+			fclose(ifh);
579c9b0
+			complain(_("couldn't allocate memory at line %d"), line);
579c9b0
+		}
579c9b0
 		memcpy(ch->ifname, p, n); 
579c9b0
 		ch->ifname[n] = 0; 
579c9b0
 		p += n; 
579c9b0
diff -up net-tools-1.60/netstat.c.coverity net-tools-1.60/netstat.c
579c9b0
--- net-tools-1.60/netstat.c.coverity	2011-04-21 14:00:20.000000000 +0200
579c9b0
+++ net-tools-1.60/netstat.c	2011-04-28 15:58:44.000000000 +0200
579c9b0
@@ -461,6 +461,8 @@ static void prg_cache_load(void)
579c9b0
 		   PATH_FD_SUFFl+1);
579c9b0
 	    strcpy(line + procfdlen + 1, direfd->d_name);
579c9b0
 	    lnamelen=readlink(line,lname,sizeof(lname)-1);
579c9b0
+	    if (lnamelen < 0)
579c9b0
+		    continue;
579c9b0
             lname[lnamelen] = '\0';  /*make it a null-terminated string*/
579c9b0
 
579c9b0
             extract_type_1_socket_inode(lname, &inode, &status);
579c9b0
@@ -902,7 +904,7 @@ static int x25_info(void)
579c9b0
                "ESTABLISHED",
579c9b0
                "RECOVERY"
579c9b0
        };
579c9b0
-       if(!(f=fopen(_PATH_PROCNET_X25, "r")))
579c9b0
+       if(!f)
579c9b0
        {
579c9b0
                if (errno != ENOENT) {
579c9b0
                        perror(_PATH_PROCNET_X25);
579c9b0
@@ -1931,6 +1933,7 @@ static int ipx_info(void)
579c9b0
     printf("\n");
579c9b0
     if ((ap = get_afntype(AF_IPX)) == NULL) {
579c9b0
 	EINTERN("netstat.c", "AF_IPX missing");
579c9b0
+	fclose(f);
579c9b0
 	return (-1);
579c9b0
     }
579c9b0
     fgets(buf, 255, f);
579c9b0
@@ -1944,6 +1947,7 @@ static int ipx_info(void)
579c9b0
 	    sport = ntohs(sport);
579c9b0
 	} else {
579c9b0
 	    EINTERN("netstat.c", _PATH_PROCNET_IPX " sport format error");
579c9b0
+	    fclose(f);
579c9b0
 	    return (-1);
579c9b0
 	}
579c9b0
 	nc = 0;
579c9b0
@@ -1954,6 +1958,7 @@ static int ipx_info(void)
579c9b0
 		dport = ntohs(dport);
579c9b0
 	    } else {
579c9b0
 		EINTERN("netstat.c", _PATH_PROCNET_IPX " dport format error");
579c9b0
+		fclose(f);
579c9b0
 		return (-1);
579c9b0
 	    }
579c9b0
 	} else