Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 8 Jul 2015 00:51:54 +0000 (UTC)
From:      Hiroki Sato <hrs@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r285261 - head/usr.sbin/jail
Message-ID:  <201507080051.t680psVG037813@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: hrs
Date: Wed Jul  8 00:51:53 2015
New Revision: 285261
URL: https://svnweb.freebsd.org/changeset/base/285261

Log:
  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

Modified:
  head/usr.sbin/jail/config.c

Modified: head/usr.sbin/jail/config.c
==============================================================================
--- head/usr.sbin/jail/config.c	Tue Jul  7 23:41:25 2015	(r285260)
+++ head/usr.sbin/jail/config.c	Wed Jul  8 00:51:53 2015	(r285261)
@@ -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));



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201507080051.t680psVG037813>