From: Christian Brauner Date: Mon, 4 Dec 2017 00:34:50 +0000 (+0100) Subject: conf: prevent null pointer dereference X-Git-Tag: lxc-3.0.0.beta1~132^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0103eb53defb5864b56131f00f05ff2e69ad369e;p=thirdparty%2Flxc.git conf: prevent null pointer dereference Signed-off-by: Christian Brauner --- diff --git a/src/lxc/conf.c b/src/lxc/conf.c index ae30b5b87..a86a6d752 100644 --- a/src/lxc/conf.c +++ b/src/lxc/conf.c @@ -1741,11 +1741,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; } @@ -1753,13 +1754,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) @@ -1798,12 +1798,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; } } @@ -1811,8 +1813,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; } diff --git a/src/lxc/utils.c b/src/lxc/utils.c index 19e6c2ee6..67c475e78 100644 --- a/src/lxc/utils.c +++ b/src/lxc/utils.c @@ -1644,7 +1644,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; }