[lxc-devel] [PATCH] refactor string conf items into common function

Dwight Engen dwight.engen at oracle.com
Mon Sep 30 21:58:03 UTC 2013


On Mon, 30 Sep 2013 14:41:41 -0500
Serge Hallyn <serge.hallyn at ubuntu.com> wrote:

> Quoting Dwight Engen (dwight.engen at oracle.com):
> > - When doing the selinux change, I noticed that there was a lot of
> >   duplication of code in handing string configuration items, so I
> >   refactored this into a common function.
> > 
> > - Added a config_string_max that can be passed a maximum acceptable
> >   length, used to limit ttydir to NAME_MAX.
> > 
> > - The behavior of config_seccomp was different than other strings:
> > if the item was already defined, then the second attempt to set it
> > would fail instead of just replacing the value. Changed to just
> > replace the value.
> > 
> > - Remove unused key and lxc_conf arguments to config_path_item().
> > 
> > Signed-off-by: Dwight Engen <dwight.engen at oracle.com>
> 
> Hi,
> 
> very nice cleanup, thanks.
> 
> Acked-by: Serge E. Hallyn <serge.hallyn at ubuntu.com>
> 
> Just one question:
> 
> 
> > @@ -938,21 +937,7 @@ static int config_tty(const char *key, const
> > char *value, static int config_ttydir(const char *key, const char
> > *value, struct lxc_conf *lxc_conf)
> >  {
> > -	char *path;
> > -
> > -	if (!value || strlen(value) == 0)
> > -		return 0;
> > -	path = strdup(value);
> > -	if (!path) {
> > -		SYSERROR("failed to strdup '%s': %m", value);
> > -		return -1;
> > -	}
> > -
> > -	if (lxc_conf->ttydir)
> > -		free(lxc_conf->ttydir);
> > -	lxc_conf->ttydir = path;
> > -
> > -	return 0;
> > +	return config_string_item_max(&lxc_conf->ttydir, value,
> > NAME_MAX+1);
> 
> Hi,
> 
> why the NAME_MAX limit here?

Because if we let them put in a ttydir bigger than NAME_MAX, then the
call to mkdir() in setup_ttydir_console() is just going to fail with
ENAMETOOLONG anyways. 

> -serge





More information about the lxc-devel mailing list