[lxc-devel] [PATCH] lxc_mount_auto_mounts: fix weirdness
Stéphane Graber
stgraber at ubuntu.com
Mon Oct 5 10:50:29 UTC 2015
On Sat, Oct 03, 2015 at 09:52:16PM +0000, Serge Hallyn wrote:
> The default_mounts[i].destination is never NULL except in the last
> 'stop here' entry. Coverity doesn't know about that and so is spewing
> a warning. In any case, let's add a more stringent check in case someone
> accidentally adds a NULL there later.
>
> Signed-off-by: Serge Hallyn <serge.hallyn at ubuntu.com>
Acked-by: Stéphane Graber <stgraber at ubuntu.com>
> ---
> src/lxc/conf.c | 22 ++++++++++++----------
> 1 file changed, 12 insertions(+), 10 deletions(-)
>
> diff --git a/src/lxc/conf.c b/src/lxc/conf.c
> index bb4c19f..80ff647 100644
> --- a/src/lxc/conf.c
> +++ b/src/lxc/conf.c
> @@ -803,16 +803,18 @@ static int lxc_mount_auto_mounts(struct lxc_conf *conf, int flags, struct lxc_ha
> return -1;
> }
> }
> - if (default_mounts[i].destination) {
> - /* will act like strdup if %r is not present */
> - destination = lxc_string_replace("%r", conf->rootfs.path ? conf->rootfs.mount : "", default_mounts[i].destination);
> - if (!destination) {
> - saved_errno = errno;
> - SYSERROR("memory allocation error");
> - free(source);
> - errno = saved_errno;
> - return -1;
> - }
> + if (!default_mounts[i].destination) {
> + ERROR("BUG: auto mounts destination %d was NULL", i);
> + return -1;
> + }
> + /* will act like strdup if %r is not present */
> + destination = lxc_string_replace("%r", conf->rootfs.path ? conf->rootfs.mount : "", default_mounts[i].destination);
> + if (!destination) {
> + saved_errno = errno;
> + SYSERROR("memory allocation error");
> + free(source);
> + errno = saved_errno;
> + return -1;
> }
> mflags = add_required_remount_flags(source, destination,
> default_mounts[i].flags);
> --
> 2.5.0
>
> _______________________________________________
> 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/20151005/428bff8f/attachment.sig>
More information about the lxc-devel
mailing list