Commit 1a6af67c authored by Dridi Boukelmoune's avatar Dridi Boukelmoune

Fail on NULL IPs in VRT

This breaks the API since some functions didn't take a VRT_CTX until now.

Closes #2860
parent 3cd5a993
...@@ -534,10 +534,12 @@ VRT_new_backend_clustered(VRT_CTX, struct vsmw_cluster *vc, ...@@ -534,10 +534,12 @@ VRT_new_backend_clustered(VRT_CTX, struct vsmw_cluster *vc,
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(vrt, VRT_BACKEND_MAGIC); CHECK_OBJ_NOTNULL(vrt, VRT_BACKEND_MAGIC);
if (vrt->path == NULL) if (vrt->path == NULL) {
assert(vrt->ipv4_suckaddr != NULL || if (vrt->ipv4_suckaddr == NULL && vrt->ipv6_suckaddr == NULL) {
vrt->ipv6_suckaddr != NULL); VRT_fail(ctx, "%s: Illegal IP", __func__);
else return (NULL);
}
} else
assert(vrt->ipv4_suckaddr == NULL && assert(vrt->ipv4_suckaddr == NULL &&
vrt->ipv6_suckaddr == NULL); vrt->ipv6_suckaddr == NULL);
......
...@@ -571,8 +571,10 @@ VRT_IP_string(VRT_CTX, VCL_IP ip) ...@@ -571,8 +571,10 @@ VRT_IP_string(VRT_CTX, VCL_IP ip)
unsigned len; unsigned len;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
if (ip == NULL) if (ip == NULL) {
VRT_fail(ctx, "%s: Illegal IP", __func__);
return (NULL); return (NULL);
}
len = WS_ReserveAll(ctx->ws); len = WS_ReserveAll(ctx->ws);
if (len == 0) { if (len == 0) {
WS_Release(ctx->ws, 0); WS_Release(ctx->ws, 0);
...@@ -836,10 +838,15 @@ VRT_memmove(void *dst, const void *src, unsigned len) ...@@ -836,10 +838,15 @@ VRT_memmove(void *dst, const void *src, unsigned len)
} }
VCL_BOOL VCL_BOOL
VRT_ipcmp(VCL_IP sua1, VCL_IP sua2) VRT_ipcmp(VRT_CTX, VCL_IP sua1, VCL_IP sua2)
{ {
if (sua1 == NULL || sua2 == NULL)
return (1); CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
if (sua1 == NULL || sua2 == NULL) {
VRT_fail(ctx, "%s: Illegal IP", __func__);
return(1);
}
return (VSA_Compare_IP(sua1, sua2)); return (VSA_Compare_IP(sua1, sua2));
} }
...@@ -851,6 +858,9 @@ VRT_blob(VRT_CTX, const char *err, const void *src, size_t len, unsigned type) ...@@ -851,6 +858,9 @@ VRT_blob(VRT_CTX, const char *err, const void *src, size_t len, unsigned type)
{ {
struct vrt_blob *p; struct vrt_blob *p;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(ctx->ws, WS_MAGIC);
p = (void *)WS_Alloc(ctx->ws, sizeof *p); p = (void *)WS_Alloc(ctx->ws, sizeof *p);
if (p == NULL) { if (p == NULL) {
VRT_fail(ctx, "Workspace overflow (%s)", err); VRT_fail(ctx, "Workspace overflow (%s)", err);
...@@ -865,7 +875,16 @@ VRT_blob(VRT_CTX, const char *err, const void *src, size_t len, unsigned type) ...@@ -865,7 +875,16 @@ VRT_blob(VRT_CTX, const char *err, const void *src, size_t len, unsigned type)
} }
int int
VRT_VSA_GetPtr(const struct suckaddr *sua, const unsigned char ** dst) VRT_VSA_GetPtr(VRT_CTX, const struct suckaddr *sua, const unsigned char ** dst)
{ {
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
AN(dst);
if (sua == NULL) {
VRT_fail(ctx, "%s: Illegal IP", __func__);
*dst = NULL;
return (-1);
}
return (VSA_GetPtr(sua, dst)); return (VSA_GetPtr(sua, dst));
} }
...@@ -60,6 +60,8 @@ ...@@ -60,6 +60,8 @@
* VRT_vcl_get moved to vcc_interface.h * VRT_vcl_get moved to vcc_interface.h
* VRT_vcl_rel emoved to vcc_interface.h * VRT_vcl_rel emoved to vcc_interface.h
* VRT_vcl_select emoved to vcc_interface.h * VRT_vcl_select emoved to vcc_interface.h
* VRT_VSA_GetPtr() changed
* VRT_ipcmp() changed
* [cache.h] WS_ReserveAll() added * [cache.h] WS_ReserveAll() added
* [cache.h] WS_Reserve(ws, 0) deprecated * [cache.h] WS_Reserve(ws, 0) deprecated
* 9.0 (2019-03-15) * 9.0 (2019-03-15)
...@@ -67,8 +69,8 @@ ...@@ -67,8 +69,8 @@
* HTTP_Copy() removed * HTTP_Copy() removed
* HTTP_Dup() added * HTTP_Dup() added
* HTTP_Clone() added * HTTP_Clone() added
* changed type of VCL_BLOB to newly introduced struct vrt_blob * * VCL_BLOB changed to newly introduced struct vrt_blob *
* changed VRT_blob() * VRT_blob() changed
* req->req_bodybytes removed * req->req_bodybytes removed
* use: AZ(ObjGetU64(req->wrk, req->body_oc, OA_LEN, &u)); * use: AZ(ObjGetU64(req->wrk, req->body_oc, OA_LEN, &u));
* struct vdi_methods .list callback signature changed * struct vdi_methods .list callback signature changed
...@@ -447,7 +449,7 @@ VCL_VOID VRT_hashdata(VRT_CTX, const char *str, ...); ...@@ -447,7 +449,7 @@ VCL_VOID VRT_hashdata(VRT_CTX, const char *str, ...);
/* Simple stuff */ /* Simple stuff */
int VRT_strcmp(const char *s1, const char *s2); int VRT_strcmp(const char *s1, const char *s2);
void VRT_memmove(void *dst, const void *src, unsigned len); void VRT_memmove(void *dst, const void *src, unsigned len);
VCL_BOOL VRT_ipcmp(VCL_IP, VCL_IP); VCL_BOOL VRT_ipcmp(VRT_CTX, VCL_IP, VCL_IP);
VCL_BLOB VRT_blob(VRT_CTX, const char *, const void *, size_t, unsigned); VCL_BLOB VRT_blob(VRT_CTX, const char *, const void *, size_t, unsigned);
VCL_VOID VRT_Rollback(VRT_CTX, VCL_HTTP); VCL_VOID VRT_Rollback(VRT_CTX, VCL_HTTP);
...@@ -513,7 +515,7 @@ VCL_BACKEND VRT_LookupDirector(VRT_CTX, VCL_STRING); ...@@ -513,7 +515,7 @@ VCL_BACKEND VRT_LookupDirector(VRT_CTX, VCL_STRING);
void VRT_DelDirector(VCL_BACKEND *); void VRT_DelDirector(VCL_BACKEND *);
/* Suckaddr related */ /* Suckaddr related */
int VRT_VSA_GetPtr(VCL_IP sua, const unsigned char ** dst); int VRT_VSA_GetPtr(VRT_CTX, VCL_IP sua, const unsigned char ** dst);
typedef int vmod_event_f(VRT_CTX, struct vmod_priv *, enum vcl_event_e); typedef int vmod_event_f(VRT_CTX, struct vmod_priv *, enum vcl_event_e);
......
...@@ -364,7 +364,7 @@ vcc_acl_emit(struct vcc *tl, const char *name, const char *rname, int anon) ...@@ -364,7 +364,7 @@ vcc_acl_emit(struct vcc *tl, const char *name, const char *rname, int anon)
Fh(tl, 0, "\tconst unsigned char *a;\n"); Fh(tl, 0, "\tconst unsigned char *a;\n");
Fh(tl, 0, "\tint fam;\n"); Fh(tl, 0, "\tint fam;\n");
Fh(tl, 0, "\n"); Fh(tl, 0, "\n");
Fh(tl, 0, "\tfam = VRT_VSA_GetPtr(p, &a);\n"); Fh(tl, 0, "\tfam = VRT_VSA_GetPtr(ctx, p, &a);\n");
Fh(tl, 0, "\tif (fam < 0) {\n"); Fh(tl, 0, "\tif (fam < 0) {\n");
Fh(tl, 0, "\t\tVRT_acl_log(ctx, \"NO_FAM %s\");\n", name); Fh(tl, 0, "\t\tVRT_acl_log(ctx, \"NO_FAM %s\");\n", name);
Fh(tl, 0, "\t\treturn(0);\n"); Fh(tl, 0, "\t\treturn(0);\n");
......
...@@ -1067,8 +1067,8 @@ static const struct cmps vcc_cmps[] = { ...@@ -1067,8 +1067,8 @@ static const struct cmps vcc_cmps[] = {
{BOOL, T_EQ, cmp_simple, "((!(\v1)) == (!(\v2)))" }, {BOOL, T_EQ, cmp_simple, "((!(\v1)) == (!(\v2)))" },
{BOOL, T_NEQ, cmp_simple, "((!(\v1)) != (!(\v2)))" }, {BOOL, T_NEQ, cmp_simple, "((!(\v1)) != (!(\v2)))" },
{IP, T_EQ, cmp_simple, "!VRT_ipcmp(\v1, \v2)" }, {IP, T_EQ, cmp_simple, "!VRT_ipcmp(ctx, \v1, \v2)" },
{IP, T_NEQ, cmp_simple, "VRT_ipcmp(\v1, \v2)" }, {IP, T_NEQ, cmp_simple, "VRT_ipcmp(ctx, \v1, \v2)" },
{IP, '~', cmp_acl, "" }, {IP, '~', cmp_acl, "" },
{IP, T_NOMATCH, cmp_acl, "!" }, {IP, T_NOMATCH, cmp_acl, "!" },
......
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