Skip to content
Permalink
Browse files

Found a sneaky way to tests VCC's vmod-tasting code.

  • Loading branch information...
bsdphk committed May 17, 2019
1 parent f4f41c5 commit 0060ee9410e0fa1d8ca9785761b790abdab7d656
@@ -14,7 +14,7 @@ varnish v1 -arg "-pvmod_path=${topbuild}/lib/libvmod_std/.libs/" \

varnish v1 -cliok "param.set vmod_path /nonexistent"

varnish v1 -errvcl {Could not load VMOD std} {
varnish v1 -errvcl {Could not find VMOD std} {
import std;
}

@@ -23,3 +23,35 @@ varnish v1 -cliok "param.set vmod_path ${topbuild}/lib/libvmod_std/.libs/"
varnish v1 -vcl+backend {
import std;
}

varnish v1 -cliok "param.set vmod_path ${tmpdir}"

shell "true > ${tmpdir}/libvmod_wrong.so"

varnish v1 -errvcl {Could not open VMOD wrong} {
import wrong;
}

shell "cp ${topbuild}/lib/libvmod_debug/.libs/libvmod_debug.so ${tmpdir}/libvmod_wrong.so"

varnish v1 -errvcl {Malformed VMOD wrong} {
import wrong;
}

varnish v1 -errvcl {Incompatible VMOD wrong0} {
import wrong0 from "${tmpdir}/libvmod_wrong.so";
}

varnish v1 -errvcl {Incompatible VMOD wrong1} {
import wrong1 from "${tmpdir}/libvmod_wrong.so";
}

varnish v1 -errvcl {Mangled VMOD wrong2} {
import wrong2 from "${tmpdir}/libvmod_wrong.so";
}

varnish v1 -errvcl {Wrong file for VMOD wrong3} {
import wrong3 from "${tmpdir}/libvmod_wrong.so";
}

shell "rm -f ${tmpdir}/libvmod_wrong.so"
@@ -769,6 +769,7 @@ VCC_New(void)
VTAILQ_INIT(&tl->sources);
VTAILQ_INIT(&tl->procs);
VTAILQ_INIT(&tl->sym_objects);
VTAILQ_INIT(&tl->sym_vmods);

tl->nsources = 0;

@@ -258,6 +258,7 @@ struct vcc {
const char *default_probe;

VTAILQ_HEAD(, symbol) sym_objects;
VTAILQ_HEAD(, symbol) sym_vmods;

unsigned unique;
unsigned vmod_count;
@@ -40,19 +40,26 @@
#include "vmod_abi.h"
#include "vsb.h"

struct vmod_open {
unsigned magic;
#define VMOD_OPEN_MAGIC 0x9995b1f3
void *hdl;
const char *err;
};

static int
vcc_path_dlopen(void *priv, const char *fn)
{
void *hdl, **pp;
struct vmod_open *vop;

AN(priv);
CAST_OBJ_NOTNULL(vop, priv, VMOD_OPEN_MAGIC);
AN(fn);

hdl = dlopen(fn, RTLD_NOW | RTLD_LOCAL);
if (hdl == NULL)
vop->hdl = dlopen(fn, RTLD_NOW | RTLD_LOCAL);
if (vop->hdl == NULL) {
vop->err = dlerror();
return (-1);
pp = priv;
*pp = hdl;
}
return (0);
}

@@ -156,7 +163,6 @@ vcc_json_wildcard(struct vcc *tl, struct symbol *msym, struct symbol *tsym)
void
vcc_ParseImport(struct vcc *tl)
{
void *hdl;
char fn[1024], *fnp, *fnpx;
char buf[256];
const char *p;
@@ -166,14 +172,17 @@ vcc_ParseImport(struct vcc *tl)
const struct vmod_data *vmd;
struct vjsn *vj;
int again = 0;
struct vmod_open vop[1];

INIT_OBJ(vop, VMOD_OPEN_MAGIC);
t1 = tl->t;
SkipToken(tl, ID); /* "import" */


ExpectErr(tl, ID);
mod = tl->t;
msym = VCC_SymbolGet(tl, SYM_NONE, SYMTAB_NOERR, XREF_NONE);
vcc_NextToken(tl);
msym = VCC_SymbolGetTok(tl, SYM_NONE, SYMTAB_NOERR, XREF_NONE, mod);

if (msym != NULL && msym->kind != SYM_VMOD) {
/*
@@ -188,13 +197,16 @@ vcc_ParseImport(struct vcc *tl)
again = 1;
} else {

msym = VCC_SymbolGet(tl, SYM_VMOD, SYMTAB_CREATE, XREF_NONE);
msym = VCC_SymbolGetTok(tl, SYM_VMOD,
SYMTAB_CREATE, XREF_NONE, mod);
ERRCHK(tl);
AN(msym);
msym->def_b = t1;
msym->def_e = tl->t;
}

VTAILQ_INSERT_TAIL(&tl->sym_vmods, msym, sideways);

if (tl->t->tok == ID) {
if (!vcc_IdIs(tl->t, "from")) {
VSB_printf(tl->sb, "Expected 'from path ...'\n");
@@ -225,12 +237,17 @@ vcc_ParseImport(struct vcc *tl)
if (!again)
msym->def_e = tl->t;


if (VFIL_searchpath(tl->vmod_path, vcc_path_dlopen, &hdl, fn, &fnpx)) {
VSB_printf(tl->sb, "Could not load VMOD %.*s\n", PF(mod));
VSB_printf(tl->sb, "\tFile name: %s\n",
fnpx != NULL ? fnpx : fn);
VSB_printf(tl->sb, "\tdlerror: %s\n", dlerror());
if (VFIL_searchpath(tl->vmod_path, vcc_path_dlopen, vop, fn, &fnpx)) {
if (vop->err == NULL) {
VSB_printf(tl->sb,
"Could not find VMOD %.*s\n", PF(mod));
} else {
VSB_printf(tl->sb,
"Could not open VMOD %.*s\n", PF(mod));
VSB_printf(tl->sb, "\tFile name: %s\n",
fnpx != NULL ? fnpx : fn);
VSB_printf(tl->sb, "\tdlerror: %s\n", vop->err);
}
vcc_ErrWhere(tl, mod);
free(fnpx);
return;
@@ -241,7 +258,7 @@ vcc_ParseImport(struct vcc *tl)
free(fnpx);

bprintf(buf, "Vmod_%.*s_Data", PF(mod));
vmd = dlsym(hdl, buf);
vmd = dlsym(vop->hdl, buf);
if (vmd == NULL) {
VSB_printf(tl->sb, "Malformed VMOD %.*s\n", PF(mod));
VSB_printf(tl->sb, "\tFile name: %s\n", fnp);
@@ -250,7 +267,7 @@ vcc_ParseImport(struct vcc *tl)
return;
}
if (vmd->vrt_major == 0 && vmd->vrt_minor == 0 &&
strcmp(vmd->abi, VMOD_ABI_Version) != 0) {
(vmd->abi == NULL || strcmp(vmd->abi, VMOD_ABI_Version) != 0)) {
VSB_printf(tl->sb, "Incompatible VMOD %.*s\n", PF(mod));
VSB_printf(tl->sb, "\tFile name: %s\n", fnp);
VSB_printf(tl->sb, "\tABI mismatch, expected <%s>, got <%s>\n",
@@ -282,7 +299,7 @@ vcc_ParseImport(struct vcc *tl)
}

if (!vcc_IdIs(mod, vmd->name)) {
VSB_printf(tl->sb, "Wrong VMOD file %.*s\n", PF(mod));
VSB_printf(tl->sb, "Wrong file for VMOD %.*s\n", PF(mod));
VSB_printf(tl->sb, "\tFile name: %s\n", fnp);
VSB_printf(tl->sb, "\tContains vmod \"%s\"\n", vmd->name);
vcc_ErrWhere(tl, mod);
@@ -298,7 +315,7 @@ vcc_ParseImport(struct vcc *tl)
vcc_ErrWhere2(tl, msym->def_b, msym->def_e);
}
if (again) {
AZ(dlclose(hdl));
AZ(dlclose(vop->hdl));
return;
}

@@ -5,8 +5,17 @@ libvmod_debug_la_SOURCES = \
vmod_debug_obj.c \
vmod_debug_dyn.c


include $(srcdir)/automake_boilerplate.am

# Allow Vmod_wrong*_Data to be exported
libvmod_debug_la_LDFLAGS = \
-export-symbols-regex 'Vmod_.*_Data' \
$(AM_LDFLAGS) \
$(VMOD_LDFLAGS) \
@SAN_LDFLAGS@


# not --strict
vmodtoolargs = --boilerplate

@@ -1,3 +1,6 @@
-esym(759, xyzzy_enum_*) // header declaration for symbol '___' defined at (___)
-esym(765, xyzzy_enum_*) // external '___' (___) could be made static

-esym(765, Vmod_wrong*_Data) // external '___' (___) could be made static
-esym(714, Vmod_wrong*_Data) // external '___' (___) could be made static
-esym(754, foo::bar) // local struct member not referenced
@@ -134,7 +134,7 @@ xyzzy_rot13_bytes(struct req *req, enum vdp_action act, void **priv,
}
}
if (i >= 0)
retval = VDP_bytes(req, VDP_FLUSH, q, i + 1);
retval = VDP_bytes(req, VDP_FLUSH, q, i + 1L);
return (retval);
}

@@ -854,3 +854,44 @@ xyzzy_sndbuf(VRT_CTX, VCL_BYTES arg)
VSLb(ctx->vsl, SLT_Debug, "SO_SNDBUF fd=%d old=%d new=%d actual=%d",
fd, oldbuf, buflen, newbuf);
}

/**********************************************************************
* For testing import code on bad vmod files (m00003.vtc)
*/

const struct vmod_data Vmod_wrong0_Data = {
.vrt_major = 0,
.vrt_minor = 0,
};

//lint -save -e835 A zero has been given as left argument to operatorp'+'
const struct vmod_data Vmod_wrong1_Data = {
.vrt_major = VRT_MAJOR_VERSION,
.vrt_minor = VRT_MINOR_VERSION + 1,
};
//lint -restore

static const struct foo {
int bar;
} foo_struct[1];

const struct vmod_data Vmod_wrong2_Data = {
.vrt_major = VRT_MAJOR_VERSION,
.vrt_minor = VRT_MINOR_VERSION,
.name = "wrongN",
.func = foo_struct,
.func_len = sizeof foo_struct,
.func_name = "foo_struct",
.proto = "blablabla",
};

const struct vmod_data Vmod_wrong3_Data = {
.vrt_major = VRT_MAJOR_VERSION,
.vrt_minor = VRT_MINOR_VERSION,
.name = "wrongN",
.func = foo_struct,
.func_len = sizeof foo_struct,
.func_name = "foo_struct",
.proto = "blablabla",
.abi = "abiblabla",
};

0 comments on commit 0060ee9

Please sign in to comment.
You can’t perform that action at this time.