]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
conf: prevent null pointer dereference
authorChristian Brauner <christian.brauner@ubuntu.com>
Mon, 4 Dec 2017 00:34:50 +0000 (01:34 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Sun, 17 Dec 2017 14:49:59 +0000 (15:49 +0100)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/conf.c
src/lxc/utils.c

index 03fae281c2fd9e8d0878d8dad517b398935e999d..09aa7b21c6e69b23c9fa9be1db2ee287e1c7e351 100644 (file)
@@ -1699,11 +1699,12 @@ static int mount_entry(const char *fsname, const char *target,
        if (ret < 0) {
                if (optional) {
                        INFO("Failed to mount \"%s\" on \"%s\" (optional): %s",
-                            fsname, target, strerror(errno));
+                            fsname ? fsname : "(null)", target, strerror(errno));
                        return 0;
                }
 
-               SYSERROR("Failed to mount \"%s\" on \"%s\"", fsname, target);
+               SYSERROR("Failed to mount \"%s\" on \"%s\"",
+                        fsname ? fsname : "(null)", target);
                return -1;
        }
 
@@ -1711,13 +1712,12 @@ static int mount_entry(const char *fsname, const char *target,
                unsigned long rqd_flags = 0;
 
                DEBUG("Remounting \"%s\" on \"%s\" to respect bind or remount "
-                     "options",
-                     fsname ? fsname : "(none)", target ? target : "(none)");
+                     "options", fsname ? fsname : "(none)", target ? target : "(none)");
 
                if (mountflags & MS_RDONLY)
                        rqd_flags |= MS_RDONLY;
 #ifdef HAVE_STATVFS
-               if (statvfs(fsname, &sb) == 0) {
+               if (fsname && statvfs(fsname, &sb) == 0) {
                        unsigned long required_flags = rqd_flags;
 
                        if (sb.f_flag & MS_NOSUID)
@@ -1756,12 +1756,14 @@ static int mount_entry(const char *fsname, const char *target,
                if (ret < 0) {
                        if (optional) {
                                INFO("Failed to mount \"%s\" on \"%s\" "
-                                    "(optional): %s", fsname, target,
+                                    "(optional): %s",
+                                    fsname ? fsname : "(null)", target,
                                     strerror(errno));
                                return 0;
                        }
 
-                       SYSERROR("Failed to mount \"%s\" on \"%s\"", fsname, target);
+                       SYSERROR("Failed to mount \"%s\" on \"%s\"",
+                                fsname ? fsname : "(null)", target);
                        return -1;
                }
        }
@@ -1769,8 +1771,8 @@ static int mount_entry(const char *fsname, const char *target,
 #ifdef HAVE_STATVFS
 skipremount:
 #endif
-       DEBUG("Mounted \"%s\" on \"%s\" with filesystem type \"%s\"", fsname,
-             target, fstype);
+       DEBUG("Mounted \"%s\" on \"%s\" with filesystem type \"%s\"",
+             fsname ? fsname : "(null)", target, fstype);
 
        return 0;
 }
index bb3ac4e9b45b751d1579f5e31a2d051aa8750e12..936603d8252d7f71beb9994e1d521c92a0f8d471 100644 (file)
@@ -1702,7 +1702,7 @@ int safe_mount(const char *src, const char *dest, const char *fstype,
        close(destfd);
        if (ret < 0) {
                errno = saved_errno;
-               SYSERROR("Failed to mount %s onto %s", src, dest);
+               SYSERROR("Failed to mount %s onto %s", src ? src : "(null)", dest);
                return ret;
        }