vcc_acl: flexelint

Ref aff516b7
    f65f7148
parent a3664ead
...@@ -54,7 +54,7 @@ struct acl_e { ...@@ -54,7 +54,7 @@ struct acl_e {
unsigned not; unsigned not;
unsigned para; unsigned para;
char *addr; char *addr;
char *fixed; const char *fixed;
struct token *t_addr; struct token *t_addr;
struct token *t_mask; struct token *t_mask;
}; };
...@@ -69,6 +69,16 @@ struct acl_e { ...@@ -69,6 +69,16 @@ struct acl_e {
return (1); \ return (1); \
} while (0) } while (0)
static void
vcl_acl_free(struct acl_e **aep)
{
AN(aep);
CHECK_OBJ_NOTNULL(*aep, VCC_ACL_E_MAGIC);
if ((*aep)->addr != NULL)
free((*aep)->addr);
FREE_OBJ(*aep);
}
static int static int
vcl_acl_cmp(const struct acl_e *ae1, const struct acl_e *ae2) vcl_acl_cmp(const struct acl_e *ae1, const struct acl_e *ae2)
{ {
...@@ -159,7 +169,7 @@ vcc_acl_chk(struct vcc *tl, const struct acl_e *ae, const int l, ...@@ -159,7 +169,7 @@ vcc_acl_chk(struct vcc *tl, const struct acl_e *ae, const int l,
return (strdup(t)); return (strdup(t));
} }
static void static struct acl_e *
vcc_acl_insert_entry(struct vcc *tl, struct acl_e *aen) vcc_acl_insert_entry(struct vcc *tl, struct acl_e *aen)
{ {
struct acl_e *ae2; struct acl_e *ae2;
...@@ -173,12 +183,12 @@ vcc_acl_insert_entry(struct vcc *tl, struct acl_e *aen) ...@@ -173,12 +183,12 @@ vcc_acl_insert_entry(struct vcc *tl, struct acl_e *aen)
VSB_cat(tl->sb, "vs:\n"); VSB_cat(tl->sb, "vs:\n");
vcc_ErrWhere(tl, aen->t_addr); vcc_ErrWhere(tl, aen->t_addr);
} }
FREE_OBJ(aen); return (NULL);
return;
} }
return (aen);
} }
static void static struct acl_e *
vcc_acl_add_entry(struct vcc *tl, const struct acl_e *ae, int l, vcc_acl_add_entry(struct vcc *tl, const struct acl_e *ae, int l,
unsigned char *u, int fam) unsigned char *u, int fam)
{ {
...@@ -191,17 +201,18 @@ vcc_acl_add_entry(struct vcc *tl, const struct acl_e *ae, int l, ...@@ -191,17 +201,18 @@ vcc_acl_add_entry(struct vcc *tl, const struct acl_e *ae, int l,
vcc_ErrWhere(tl, ae->t_mask); vcc_ErrWhere(tl, ae->t_mask);
else else
vcc_ErrWhere(tl, ae->t_addr); vcc_ErrWhere(tl, ae->t_addr);
return; return (NULL);
} }
if (fam == PF_INET6 && ae->mask > 128) { if (fam == PF_INET6 && ae->mask > 128) {
VSB_printf(tl->sb, VSB_printf(tl->sb,
"Too wide mask (/%u) for IPv6 address\n", ae->mask); "Too wide mask (/%u) for IPv6 address\n", ae->mask);
vcc_ErrWhere(tl, ae->t_mask); vcc_ErrWhere(tl, ae->t_mask);
return; return (NULL);
} }
/* Make a copy from the template */ /* Make a copy from the template */
ALLOC_OBJ(aen, VCC_ACL_E_MAGIC); ALLOC_OBJ(aen, VCC_ACL_E_MAGIC);
AN(aen);
*aen = *ae; *aen = *ae;
aen->fixed = vcc_acl_chk(tl, ae, l, u, fam); aen->fixed = vcc_acl_chk(tl, ae, l, u, fam);
...@@ -214,7 +225,9 @@ vcc_acl_add_entry(struct vcc *tl, const struct acl_e *ae, int l, ...@@ -214,7 +225,9 @@ vcc_acl_add_entry(struct vcc *tl, const struct acl_e *ae, int l,
assert(l + 1UL <= sizeof aen->data); assert(l + 1UL <= sizeof aen->data);
memcpy(aen->data + 1L, u, l); memcpy(aen->data + 1L, u, l);
vcc_acl_insert_entry(tl, aen); if (vcc_acl_insert_entry(tl, aen) == NULL)
vcl_acl_free(&aen);
return (aen);
} }
static void static void
...@@ -288,7 +301,7 @@ vcc_acl_try_getaddrinfo(struct vcc *tl, struct acl_e *ae) ...@@ -288,7 +301,7 @@ vcc_acl_try_getaddrinfo(struct vcc *tl, struct acl_e *ae)
u = (void*)&sin4->sin_addr; u = (void*)&sin4->sin_addr;
if (ae->t_mask == NULL) if (ae->t_mask == NULL)
ae->mask = 32; ae->mask = 32;
vcc_acl_add_entry(tl, ae, 4, u, res->ai_family); (void) vcc_acl_add_entry(tl, ae, 4, u, res->ai_family);
break; break;
case PF_INET6: case PF_INET6:
assert(PF_INET6 < 256); assert(PF_INET6 < 256);
...@@ -297,7 +310,7 @@ vcc_acl_try_getaddrinfo(struct vcc *tl, struct acl_e *ae) ...@@ -297,7 +310,7 @@ vcc_acl_try_getaddrinfo(struct vcc *tl, struct acl_e *ae)
u = (void*)&sin6->sin6_addr; u = (void*)&sin6->sin6_addr;
if (ae->t_mask == NULL) if (ae->t_mask == NULL)
ae->mask = 128; ae->mask = 128;
vcc_acl_add_entry(tl, ae, 16, u, res->ai_family); (void) vcc_acl_add_entry(tl, ae, 16, u, res->ai_family);
break; break;
default: default:
continue; continue;
...@@ -343,7 +356,7 @@ vcc_acl_try_netnotation(struct vcc *tl, struct acl_e *ae) ...@@ -343,7 +356,7 @@ vcc_acl_try_netnotation(struct vcc *tl, struct acl_e *ae)
} }
if (ae->t_mask == NULL) if (ae->t_mask == NULL)
ae->mask = 8 + 8 * i; ae->mask = 8 + 8 * i;
vcc_acl_add_entry(tl, ae, 4, b, AF_INET); (void) vcc_acl_add_entry(tl, ae, 4, b, AF_INET);
return (1); return (1);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment