diff --git a/miniupnpd/pf/obsdrdr.c b/miniupnpd/pf/obsdrdr.c index 5d323e1..7614f06 100644 --- a/miniupnpd/pf/obsdrdr.c +++ b/miniupnpd/pf/obsdrdr.c @@ -470,10 +470,15 @@ int add_nat_rule(const char * ifname, return r; } +/* + * returns: 0 : OK + * -1 : ERROR + * -2 : Rule not found + */ static int delete_nat_rule(const char * ifname, unsigned short iport, int proto, in_addr_t iaddr) { - int i, n; + int i, n, r; unsigned int tnum; struct pfioc_rule pr; UNUSED(ifname); @@ -492,20 +497,21 @@ delete_nat_rule(const char * ifname, unsigned short iport, int proto, in_addr_t if(ioctl(dev, DIOCGETRULES, &pr) < 0) { syslog(LOG_ERR, "ioctl(dev, DIOCGETRULES, ...): %m"); - goto error; + return -1; } n = pr.nr; #ifdef PF_RELEASETICKETS tnum = pr.ticket; #endif /* PF_RELEASETICKETS */ + r = -2; /* not found */ for(i=0; i= n) - goto error; + r = -1; #ifdef PF_RELEASETICKETS tnum = pr.ticket; #endif /* PF_RELEASETICKETS */ + if(index >= n) + goto error; pr.nr = index; if(ioctl(dev, DIOCGETRULE, &pr) < 0) { syslog(LOG_ERR, "ioctl(dev, DIOCGETRULE): %m"); - release_ticket(dev, tnum); goto error; } *proto = pr.rule.proto; @@ -1370,10 +1397,10 @@ get_redirect_rule_by_index(int index, } if(timestamp) *timestamp = get_timestamp(*eport, *proto); - release_ticket(dev, tnum); - return 0; + r = 0; error: - return -1; + release_ticket(dev, tnum); + return r; } /* return an (malloc'ed) array of "external" port for which there is @@ -1457,7 +1484,9 @@ get_portmappings_in_range(unsigned short startport, unsigned short endport, return array; } -/* update the port mapping internal port, description and timestamp */ +/* update the port mapping internal port, description and timestamp + * returns: 0 : OK + * -1 : Error */ int update_portmapping(const char * ifname, unsigned short eport, int proto, unsigned short iport, const char * desc,