[4.1] 83d642b Sanitize the VFIL_searchpath() caling convention to not need throwing away const.
Lasse Karstensen
lkarsten at varnish-software.com
Thu Jan 14 15:15:12 CET 2016
commit 83d642bb4c615c2675fbbe1f34484af5e4c1fc4b
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Fri Jan 8 21:14:11 2016 +0000
Sanitize the VFIL_searchpath() caling convention to not need throwing
away const.
diff --git a/bin/varnishd/mgt/mgt_vcl.c b/bin/varnishd/mgt/mgt_vcl.c
index 7d51690..ae2f898 100644
--- a/bin/varnishd/mgt/mgt_vcl.c
+++ b/bin/varnishd/mgt/mgt_vcl.c
@@ -282,12 +282,13 @@ mcf_vcl_load(struct cli *cli, const char * const *av, void *priv)
}
VFIL_setpath(&vcl_path, mgt_vcl_dir);
- fn = TRUST_ME(av[3]);
- if (VFIL_searchpath(vcl_path, NULL, &vcl, &fn)) {
+ if (VFIL_searchpath(vcl_path, NULL, &vcl, av[3], &fn)) {
VCLI_Out(cli, "Cannot open '%s'", fn != NULL ? fn : av[3]);
+ REPLACE(fn, NULL);
VCLI_SetResult(cli, CLIS_PARAM);
return;
}
+ REPLACE(fn, NULL);
mgt_new_vcl(cli, av[2], vcl, av[4], 0);
free(vcl);
diff --git a/include/vfil.h b/include/vfil.h
index 4269fe0..a542e4d 100644
--- a/include/vfil.h
+++ b/include/vfil.h
@@ -39,5 +39,5 @@ int VFIL_allocate(int fd, off_t size, int insist);
void VFIL_setpath(struct vfil_path**, const char *path);
typedef int vfil_path_func_f(void *priv, const char *fn);
int VFIL_searchpath(const struct vfil_path *, vfil_path_func_f *func,
- void *priv, char **fn);
+ void *priv, const char *fni, char **fno);
diff --git a/lib/libvarnish/vfil.c b/lib/libvarnish/vfil.c
index b6bdc9e..319c3e1 100644
--- a/lib/libvarnish/vfil.c
+++ b/lib/libvarnish/vfil.c
@@ -298,41 +298,38 @@ vfil_path_openfile(void *priv, const char *fn)
int
VFIL_searchpath(const struct vfil_path *vp, vfil_path_func_f *func, void *priv,
- char **fnp)
+ const char *fni, char **fno)
{
struct vsb *vsb;
struct vfil_dir *vd;
- const char *fn;
int i, e;
CHECK_OBJ_NOTNULL(vp, VFIL_PATH_MAGIC);
- AN(fnp);
- AN(*fnp);
- fn = *fnp;
- *fnp = NULL;
+ AN(fno);
+ *fno = NULL;
if (func == NULL) {
func = vfil_path_openfile;
AN(priv);
}
- if (*fn == '/') {
- i = func(priv, fn);
+ if (*fni == '/') {
+ i = func(priv, fni);
if (i <= 0)
- REPLACE(*fnp, fn);
+ REPLACE(*fno, fni);
return (i);
}
vsb = VSB_new_auto();
AN(vsb);
VTAILQ_FOREACH(vd, &vp->paths, list) {
VSB_clear(vsb);
- VSB_printf(vsb, "%s/%s", vd->dir, fn);
+ VSB_printf(vsb, "%s/%s", vd->dir, fni);
AZ(VSB_finish(vsb));
i = func(priv, VSB_data(vsb));
if (i <= 0) {
e = errno;
- *fnp = strdup(VSB_data(vsb));
- AN(*fnp);
+ *fno = strdup(VSB_data(vsb));
+ AN(*fno);
VSB_delete(vsb);
errno = e;
return (i);
diff --git a/lib/libvcc/vcc_compile.c b/lib/libvcc/vcc_compile.c
index c52dd8d..f35e07b 100644
--- a/lib/libvcc/vcc_compile.c
+++ b/lib/libvcc/vcc_compile.c
@@ -450,7 +450,7 @@ vcc_destroy_source(struct source *sp)
/*--------------------------------------------------------------------*/
static struct source *
-vcc_file_source(const struct vcp * const vcp, struct vsb *sb, char *fn)
+vcc_file_source(const struct vcp * const vcp, struct vsb *sb, const char *fn)
{
char *f, *fnp;
struct source *sp;
@@ -460,8 +460,7 @@ vcc_file_source(const struct vcp * const vcp, struct vsb *sb, char *fn)
return (NULL);
}
f = NULL;
- fnp = fn;
- if (VFIL_searchpath(vcp->vcl_path, NULL, &f, &fnp) || f == NULL) {
+ if (VFIL_searchpath(vcp->vcl_path, NULL, &f, fn, &fnp) || f == NULL) {
VSB_printf(sb, "Cannot read file '%s' (%s)\n",
fnp != NULL ? fnp : fn, strerror(errno));
return (NULL);
diff --git a/lib/libvcc/vcc_vmod.c b/lib/libvcc/vcc_vmod.c
index 0a165c7..0f90e4f 100644
--- a/lib/libvcc/vcc_vmod.c
+++ b/lib/libvcc/vcc_vmod.c
@@ -49,7 +49,6 @@ vcc_path_dlopen(void *priv, const char *fn)
AN(priv);
AN(fn);
-fprintf(stderr, "TRY <%s>\n", fn);
hdl = dlopen(fn, RTLD_NOW | RTLD_LOCAL);
if (hdl == NULL)
return (1);
@@ -126,9 +125,8 @@ vcc_ParseImport(struct vcc *tl)
SkipToken(tl, ';');
- fnp = fn;
if (VFIL_searchpath(tl->param->vmod_path,
- vcc_path_dlopen, &hdl, &fnp)) {
+ vcc_path_dlopen, &hdl, fn, &fnp)) {
VSB_printf(tl->sb, "Could not load VMOD %.*s\n", PF(mod));
VSB_printf(tl->sb, "\tFile name: %s\n", fnp != NULL ? fnp : fn);
VSB_printf(tl->sb, "\tdlerror: %s\n", dlerror());
More information about the varnish-commit
mailing list