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