Commit 26bb5f02 authored by Pål Hermunn Johansen's avatar Pål Hermunn Johansen

Prevent storage backends name collisions

This is a backport of 98676319 by Dridi Boukelmoune, but this patch
is a bit different from the original.

Now name collisions with transient will be reported in a sane way
instead of producing an assert. Normal name collisions are also more
readable.

The test case is unmodified, thanks to resent back porting efforts in
varnishtest.

Fixes #2321

Conflicts:
	bin/varnishd/storage/mgt_stevedore.c
parent 6556c563
......@@ -116,6 +116,28 @@ static const struct choice STV_choice[] = {
{ NULL, NULL }
};
static void
stv_check_ident(const char *spec, const char *ident)
{
struct stevedore *stv;
unsigned found = 0;
if (!strcmp(ident, TRANSIENT_STORAGE))
found = (stv_transient != NULL);
else {
VTAILQ_FOREACH(stv, &stv_stevedores, list) {
CHECK_OBJ(stv, STEVEDORE_MAGIC);
if (!strcmp(stv->ident, ident)) {
found = 1;
break;
}
}
}
if (found)
ARGV_ERR("(-s %s) '%s' is already defined\n", spec, ident);
}
void
STV_Config(const char *spec)
{
......@@ -170,17 +192,12 @@ STV_Config(const char *spec)
bprintf(stv->ident, "%.*s", l, spec);
}
VTAILQ_FOREACH(stv2, &stv_stevedores, list) {
if (strcmp(stv2->ident, stv->ident))
continue;
ARGV_ERR("(-s%s=%s) already defined once\n",
stv->ident, stv->name);
}
stv_check_ident(spec, stv->ident);
if (stv->init != NULL)
stv->init(stv, ac, av);
else if (ac != 0)
ARGV_ERR("(-s%s) too many arguments\n", stv->name);
ARGV_ERR("(-s %s) too many arguments\n", stv->name);
AN(stv->alloc);
if (stv->allocobj == NULL)
......
varnishtest "Storage name collisions"
# intentional collision
shell -err -expect "Error: (-s main=malloc,100m) 'main' is already defined" {
exec varnishd -a :0 -f '' -n ${tmpdir} \
-s main=malloc,10m -s main=malloc,100m
}
# pseudo-accidental collision
shell -err -expect "Error: (-s s0=malloc,100m) 's0' is already defined" {
exec varnishd -a :0 -f '' -n ${tmpdir} \
-s malloc,10m -s s0=malloc,100m
}
# Transient collision
shell -err -expect "Error: (-s Transient=malloc,100m) 'Transient' is already defined" {
exec varnishd -a :0 -f '' -n ${tmpdir} \
-s Transient=malloc,10m -s Transient=malloc,100m
}
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