[lxc-devel] [PATCH 1/2] coverity: don't use newname after null check
Stéphane Graber
stgraber at ubuntu.com
Sat Aug 16 01:00:20 UTC 2014
On Mon, Aug 11, 2014 at 02:10:04PM +0000, Serge Hallyn wrote:
> Actually, get rid of the temporary variables, and set newname
> and lxcpath to usable values if they were NULL.
>
> Signed-off-by: Serge Hallyn <serge.hallyn at ubuntu.com>
Acked-by: Stéphane Graber <stgraber at ubuntu.com>
> ---
> src/lxc/lxccontainer.c | 16 +++++++++-------
> 1 file changed, 9 insertions(+), 7 deletions(-)
>
> diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c
> index 38197d6..0cf21ce 100644
> --- a/src/lxc/lxccontainer.c
> +++ b/src/lxc/lxccontainer.c
> @@ -2726,7 +2726,6 @@ static struct lxc_container *lxcapi_clone(struct lxc_container *c, const char *n
> struct lxc_container *c2 = NULL;
> char newpath[MAXPATHLEN];
> int ret, storage_copied = 0;
> - const char *n, *l;
> char *origroot = NULL;
> struct clone_update_data data;
> FILE *fout;
> @@ -2744,9 +2743,11 @@ static struct lxc_container *lxcapi_clone(struct lxc_container *c, const char *n
> }
>
> // Make sure the container doesn't yet exist.
> - n = newname ? newname : c->name;
> - l = lxcpath ? lxcpath : c->get_config_path(c);
> - ret = snprintf(newpath, MAXPATHLEN, "%s/%s/config", l, n);
> + if (!newname)
> + newname = c->name;
> + if (!lxcpath)
> + lxcpath = c->get_config_path(c);
> + ret = snprintf(newpath, MAXPATHLEN, "%s/%s/config", lxcpath, newname);
> if (ret < 0 || ret >= MAXPATHLEN) {
> SYSERROR("clone: failed making config pathname");
> goto out;
> @@ -2776,7 +2777,7 @@ static struct lxc_container *lxcapi_clone(struct lxc_container *c, const char *n
> fclose(fout);
> c->lxc_conf->rootfs.path = origroot;
>
> - sprintf(newpath, "%s/%s/rootfs", l, n);
> + sprintf(newpath, "%s/%s/rootfs", lxcpath, newname);
> if (mkdir(newpath, 0755) < 0) {
> SYSERROR("error creating %s", newpath);
> goto out;
> @@ -2789,9 +2790,10 @@ static struct lxc_container *lxcapi_clone(struct lxc_container *c, const char *n
> }
> }
>
> - c2 = lxc_container_new(n, l);
> + c2 = lxc_container_new(newname, lxcpath);
> if (!c2) {
> - ERROR("clone: failed to create new container (%s %s)", n, l);
> + ERROR("clone: failed to create new container (%s %s)", newname,
> + lxcpath);
> goto out;
> }
>
> --
> 2.1.0.rc1
>
> _______________________________________________
> lxc-devel mailing list
> lxc-devel at lists.linuxcontainers.org
> http://lists.linuxcontainers.org/listinfo/lxc-devel
--
Stéphane Graber
Ubuntu developer
http://www.ubuntu.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20140815/e13dc054/attachment.sig>
More information about the lxc-devel
mailing list