lxc_mount_auto_mounts: fix weirdness

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@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
This commit is contained in:
Serge Hallyn 2015-10-03 21:52:16 +00:00 committed by Stéphane Graber
parent 2c79e91b4b
commit cc4fd5064b

View File

@ -803,16 +803,18 @@ static int lxc_mount_auto_mounts(struct lxc_conf *conf, int flags, struct lxc_ha
return -1; return -1;
} }
} }
if (default_mounts[i].destination) { if (!default_mounts[i].destination) {
/* will act like strdup if %r is not present */ ERROR("BUG: auto mounts destination %d was NULL", i);
destination = lxc_string_replace("%r", conf->rootfs.path ? conf->rootfs.mount : "", default_mounts[i].destination); return -1;
if (!destination) { }
saved_errno = errno; /* will act like strdup if %r is not present */
SYSERROR("memory allocation error"); destination = lxc_string_replace("%r", conf->rootfs.path ? conf->rootfs.mount : "", default_mounts[i].destination);
free(source); if (!destination) {
errno = saved_errno; saved_errno = errno;
return -1; SYSERROR("memory allocation error");
} free(source);
errno = saved_errno;
return -1;
} }
mflags = add_required_remount_flags(source, destination, mflags = add_required_remount_flags(source, destination,
default_mounts[i].flags); default_mounts[i].flags);