luci-lib-ip: explicitly initialize address scope value
authorJo-Philipp Wich <jo@mein.io>
Thu, 23 Jan 2020 11:31:36 +0000 (12:31 +0100)
committerJo-Philipp Wich <jo@mein.io>
Thu, 23 Jan 2020 11:33:49 +0000 (12:33 +0100)
Explicitly initialize the address scope value to zero in parse_cidr() and
L_setaddr() to avoid stray scope identifiers getting added when formatting
the address object as string.

Fixes: 1d2b4c777 ("luci-lib-ip: support scoped IPv6 addresses")
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
libs/luci-lib-ip/src/ip.c

index 34a120d1ae2dc5892d2d0167b0af4b906c326a8c..698cf9a11f85d289518eaa9397ba9a3f6369c559 100644 (file)
@@ -216,6 +216,9 @@ static bool parse_cidr(const char *dest, cidr_t *pp)
                if (pp->scope == 0)
                        return false;
        }
+       else {
+               pp->scope = 0;
+       }
 
        if (p)
        {
@@ -327,18 +330,21 @@ static void L_setaddr(struct lua_State *L, const char *name,
                p->family = AF_INET;
                p->bits = (bits < 0) ? AF_BITS(AF_INET) : bits;
                p->addr.v4 = *(struct in_addr *)addr;
+               p->scope = 0;
        }
        else if (family == AF_INET6)
        {
                p->family = AF_INET6;
                p->bits = (bits < 0) ? AF_BITS(AF_INET6) : bits;
                p->addr.v6 = *(struct in6_addr *)addr;
+               p->scope = 0;
        }
        else
        {
                p->family = AF_PACKET;
                p->bits = (bits < 0) ? AF_BITS(AF_PACKET) : bits;
                p->addr.mac = *(struct ether_addr *)addr;
+               p->scope = 0;
        }
 
        luaL_getmetatable(L, LUCI_IP_CIDR);