summaryrefslogtreecommitdiffstats
path: root/contrib/ipfilter/tools/ipfs.c
diff options
context:
space:
mode:
authorguido <guido@FreeBSD.org>2006-08-16 11:51:32 +0000
committerguido <guido@FreeBSD.org>2006-08-16 11:51:32 +0000
commit092f5d1218f4867a87b382d75613b9d2b3e56c18 (patch)
treee49755bc5470450d9acf44918f68b5acd3915e51 /contrib/ipfilter/tools/ipfs.c
parent9749beb9e35afd40d054e5592764d50ed069a890 (diff)
downloadFreeBSD-src-092f5d1218f4867a87b382d75613b9d2b3e56c18.zip
FreeBSD-src-092f5d1218f4867a87b382d75613b9d2b3e56c18.tar.gz
Import IP Filter 4.1.13
Diffstat (limited to 'contrib/ipfilter/tools/ipfs.c')
-rw-r--r--contrib/ipfilter/tools/ipfs.c55
1 files changed, 38 insertions, 17 deletions
diff --git a/contrib/ipfilter/tools/ipfs.c b/contrib/ipfilter/tools/ipfs.c
index 767dffb..4479d19 100644
--- a/contrib/ipfilter/tools/ipfs.c
+++ b/contrib/ipfilter/tools/ipfs.c
@@ -458,21 +458,19 @@ char *file;
i = read(sfd, &ips, sizeof(ips));
if (i == -1) {
perror("read");
- close(sfd);
- return 1;
+ goto freeipshead;
}
if (i == 0)
break;
if (i != sizeof(ips)) {
fprintf(stderr, "state:incomplete read: %d != %d\n",
i, (int)sizeof(ips));
- close(sfd);
- return 1;
+ goto freeipshead;
}
is = (ipstate_save_t *)malloc(sizeof(*is));
- if(!is) {
+ if (is == NULL) {
fprintf(stderr, "malloc failed\n");
- return 1;
+ goto freeipshead;
}
bcopy((char *)&ips, (char *)is, sizeof(ips));
@@ -510,7 +508,7 @@ char *file;
obj.ipfo_size = sizeof(*is);
obj.ipfo_type = IPFOBJ_STATESAVE;
- for (is = ipshead; is; is = is->ips_next) {
+ while ((is = ipshead) != NULL) {
if (opts & OPT_VERBOSE)
printf("Loading new state table entry\n");
if (is->ips_is.is_flags & SI_NEWFR) {
@@ -522,7 +520,7 @@ char *file;
if (!(opts & OPT_DONOTHING))
if (ioctl(fd, SIOCSTPUT, &obj)) {
perror("SIOCSTPUT");
- return 1;
+ goto freeipshead;
}
if (is->ips_is.is_flags & SI_NEWFR) {
@@ -532,9 +530,21 @@ char *file;
if (is1->ips_rule == (frentry_t *)&is->ips_rule)
is1->ips_rule = is->ips_rule;
}
+
+ ipshead = is->ips_next;
+ free(is);
}
return 0;
+
+freeipshead:
+ while ((is = ipshead) != NULL) {
+ ipshead = is->ips_next;
+ free(is);
+ }
+ if (sfd != -1)
+ close(sfd);
+ return 1;
}
@@ -573,21 +583,21 @@ char *file;
i = read(nfd, &ipn, sizeof(ipn));
if (i == -1) {
perror("read");
- close(nfd);
- return 1;
+ goto freenathead;
}
if (i == 0)
break;
if (i != sizeof(ipn)) {
fprintf(stderr, "nat:incomplete read: %d != %d\n",
i, (int)sizeof(ipn));
- close(nfd);
- return 1;
+ goto freenathead;
}
in = (nat_save_t *)malloc(ipn.ipn_dsize);
- if (!in)
- break;
+ if (in == NULL) {
+ fprintf(stderr, "nat:cannot malloc nat save atruct\n");
+ goto freenathead;
+ }
if (ipn.ipn_dsize > sizeof(ipn)) {
n = ipn.ipn_dsize - sizeof(ipn);
@@ -600,8 +610,7 @@ char *file;
fprintf(stderr,
"nat:incomplete read: %d != %d\n",
i, n);
- close(nfd);
- return 1;
+ goto freenathead;
}
}
}
@@ -643,7 +652,7 @@ char *file;
obj.ipfo_rev = IPFILTER_VERSION;
obj.ipfo_type = IPFOBJ_NATSAVE;
- for (in = ipnhead; in; in = in->ipn_next) {
+ while ((in = ipnhead) != NULL) {
if (opts & OPT_VERBOSE)
printf("Loading new NAT table entry\n");
nat = &in->ipn_nat;
@@ -668,9 +677,21 @@ char *file;
if (in1->ipn_rule == &in->ipn_fr)
in1->ipn_rule = nat->nat_fr;
}
+
+ ipnhead = in->ipn_next;
+ free(in);
}
return 0;
+
+freenathead:
+ while ((in = ipnhead) != NULL) {
+ ipnhead = in->ipn_next;
+ free(in);
+ }
+ if (nfd != -1)
+ close(nfd);
+ return 1;
}
OpenPOWER on IntegriCloud