On Wed, Aug 01, 2018 at 01:27:48AM +0200, Klemens Nanni wrote:
> Updated diff bringing this function in line with its counterparts by
> using `mask' the same way.
> 
> If a mask was specified, `mask' would always equal to `bits' as returned
> by inet_net_pton(), so avoid the duplicate.
> 
> While here, directly use the destination size in memcpy() instead of
> hardcoding its type.
I'd  still like to see this in as it makes host_v4() consistent with
host_v6() with regard to `mask' handling.

OK?

Index: pfctl_parser.c
===================================================================
RCS file: /cvs/src/sbin/pfctl/pfctl_parser.c,v
retrieving revision 1.326
diff -u -p -r1.326 pfctl_parser.c
--- pfctl_parser.c      31 Jul 2018 22:48:04 -0000      1.326
+++ pfctl_parser.c      31 Jul 2018 23:25:01 -0000
@@ -1727,11 +1727,10 @@ host_v4(const char *s, int mask)
 {
        struct node_host        *h = NULL;
        struct in_addr           ina;
-       int                      bits = 32;
 
-       memset(&ina, 0, sizeof(struct in_addr));
-       if (strrchr(s, '/') != NULL) {
-               if ((bits = inet_net_pton(AF_INET, s, &ina, sizeof(ina))) == -1)
+       memset(&ina, 0, sizeof(ina));
+       if (mask > -1) {
+               if (inet_net_pton(AF_INET, s, &ina, sizeof(ina)) == -1)
                        return (NULL);
        } else {
                if (inet_pton(AF_INET, s, &ina) != 1)
@@ -1744,7 +1743,7 @@ host_v4(const char *s, int mask)
        h->ifname = NULL;
        h->af = AF_INET;
        h->addr.v.a.addr.addr32[0] = ina.s_addr;
-       set_ipmask(h, bits);
+       set_ipmask(h, mask > -1 ? mask : 32);
        h->next = NULL;
        h->tail = h;
 

Reply via email to