From 3c6c216f16bc709c4ec041197fc43da17b24d02d Mon Sep 17 00:00:00 2001 From: hrs Date: Wed, 8 Jul 2015 00:51:53 +0000 Subject: Fix offset calculation in variable substitution in jail.conf. The following did not work correctly: A="A_${B}_C_${D}" B="BBBBB" D="DDDD_${E}_FFFFF" E="EEEEE" PR: 189139 Reviewed by: jamie Differential Revision: https://reviews.freebsd.org/D3018 --- usr.sbin/jail/config.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'usr.sbin/jail') diff --git a/usr.sbin/jail/config.c b/usr.sbin/jail/config.c index 5820209..1dd04498 100644 --- a/usr.sbin/jail/config.c +++ b/usr.sbin/jail/config.c @@ -130,9 +130,8 @@ load_config(void) struct cfjail *j, *tj, *wj; struct cfparam *p, *vp, *tp; struct cfstring *s, *vs, *ns; - struct cfvar *v; + struct cfvar *v, *vv; char *ep; - size_t varoff; int did_self, jseq, pgen; if (!strcmp(cfname, "-")) { @@ -191,7 +190,6 @@ load_config(void) p->gen = ++pgen; find_vars: TAILQ_FOREACH(s, &p->val, tq) { - varoff = 0; while ((v = STAILQ_FIRST(&s->vars))) { TAILQ_FOREACH(vp, &j->params, tq) if (!strcmp(vp->name, v->name)) @@ -233,11 +231,13 @@ load_config(void) goto bad_var; } s->s = erealloc(s->s, s->len + vs->len + 1); - memmove(s->s + v->pos + varoff + vs->len, - s->s + v->pos + varoff, - s->len - (v->pos + varoff) + 1); - memcpy(s->s + v->pos + varoff, vs->s, vs->len); - varoff += vs->len; + memmove(s->s + v->pos + vs->len, + s->s + v->pos, + s->len - v->pos + 1); + memcpy(s->s + v->pos, vs->s, vs->len); + vv = v; + while ((vv = STAILQ_NEXT(vv, tq))) + vv->pos += vs->len; s->len += vs->len; while ((vs = TAILQ_NEXT(vs, tq))) { ns = emalloc(sizeof(struct cfstring)); -- cgit v1.1