net-tools/net-tools-1.60-coverity.patch
2011-12-06 19:15:09 +01:00

246 lines
7.9 KiB
Diff

diff -up net-tools-1.60/ipmaddr.c.coverity net-tools-1.60/ipmaddr.c
--- net-tools-1.60/ipmaddr.c.coverity 2011-11-21 02:31:57.000000000 +0100
+++ net-tools-1.60/ipmaddr.c 2011-12-06 15:16:27.210032670 +0100
@@ -160,6 +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;
@@ -174,7 +179,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 +193,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 +204,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 +241,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 2011-11-21 02:31:57.000000000 +0100
+++ net-tools-1.60/iptunnel.c 2011-12-06 15:17:25.231307304 +0100
@@ -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 2011-11-21 02:31:57.000000000 +0100
+++ net-tools-1.60/lib/inet.c 2011-12-06 15:20:21.183107604 +0100
@@ -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/masq_info.c.coverity net-tools-1.60/lib/masq_info.c
--- net-tools-1.60/lib/masq_info.c.coverity 2011-11-21 02:31:57.000000000 +0100
+++ net-tools-1.60/lib/masq_info.c 2011-12-06 15:22:21.768600077 +0100
@@ -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 2011-11-21 02:31:57.000000000 +0100
+++ net-tools-1.60/lib/netrom_gr.c 2011-12-06 15:23:34.471691164 +0100
@@ -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-11-21 02:31:57.000000000 +0100
+++ net-tools-1.60/lib/x25.c 2011-12-06 15:24:37.189907079 +0100
@@ -105,7 +105,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", X25_errmsg, orig);
diff -up net-tools-1.60/nameif.c.coverity net-tools-1.60/nameif.c
--- net-tools-1.60/nameif.c.coverity 2011-12-06 15:12:17.000000000 +0100
+++ net-tools-1.60/nameif.c 2011-12-06 15:28:06.417291375 +0100
@@ -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,6 @@ 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 +178,11 @@ void readconf(void)
n = strcspn(p, " \t");
if (n > IFNAMSIZ-1)
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-12-06 15:12:17.000000000 +0100
+++ net-tools-1.60/netstat.c 2011-12-06 15:32:36.060920366 +0100
@@ -434,6 +434,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*/
if (extract_type_1_socket_inode(lname, &inode) < 0)
@@ -833,7 +835,7 @@ static int x25_info(void)
"ESTABLISHED",
"RECOVERY"
};
- if(!(f=proc_fopen(_PATH_PROCNET_X25)))
+ if(!f)
{
if (errno != ENOENT) {
perror(_PATH_PROCNET_X25);
@@ -1716,6 +1718,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);
@@ -1729,6 +1732,7 @@ static int ipx_info(void)
sport = ntohs(sport);
} else {
EINTERN("netstat.c", "ipx socket format error in source port");
+ fclose(f);
return (-1);
}
nc = 0;
@@ -1739,6 +1743,7 @@ static int ipx_info(void)
dport = ntohs(dport);
} else {
EINTERN("netstat.c", "ipx soket format error in destination port");
+ fclose(f);
return (-1);
}
} else