]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
lxc_mount_auto_mounts: fix weirdness
authorSerge Hallyn <serge.hallyn@ubuntu.com>
Sat, 3 Oct 2015 21:52:16 +0000 (21:52 +0000)
committerStéphane Graber <stgraber@ubuntu.com>
Wed, 7 Oct 2015 16:19:25 +0000 (17:19 +0100)
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>
src/lxc/conf.c

index 4b84442e95839286e8f7a48d02aad53654932321..7c45301d747bf32c400244bd89c8aea85fc5b7a7 100644 (file)
@@ -788,16 +788,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);