From 405b048dc82a8695b8a400524787243f3898cbd6 Mon Sep 17 00:00:00 2001
From: wujing <wujing50@huawei.com>
Date: Tue, 21 Jul 2020 17:30:17 +0800
Subject: [PATCH 5/5] solve coredump bug caused by fstype being NULL during
 mount

Signed-off-by: wujing <wujing50@huawei.com>
---
 src/lxc/lsm/selinux.c | 3 +--
 src/lxc/utils.c       | 7 ++++---
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/lxc/lsm/selinux.c b/src/lxc/lsm/selinux.c
index ceac0889..837a3da3 100644
--- a/src/lxc/lsm/selinux.c
+++ b/src/lxc/lsm/selinux.c
@@ -68,7 +68,6 @@ static int selinux_process_label_set(const char *inlabel, struct lxc_conf *conf,
 
 	label = inlabel ? inlabel : conf->lsm_se_context;
 	if (!label) {
-
 		label = DEFAULT_LABEL;
 	}
 
@@ -273,7 +272,7 @@ static int selinux_relabel(const char *path, const char *label, bool shared)
 {
 	__do_free char *tmp_file_label = NULL;
 
-	if (label == NULL) {
+	if (path == NULL || label == NULL) {
 		return 0;
 	}
 
diff --git a/src/lxc/utils.c b/src/lxc/utils.c
index 5ec6117f..95c00cfe 100644
--- a/src/lxc/utils.c
+++ b/src/lxc/utils.c
@@ -1230,7 +1230,7 @@ int safe_mount(const char *src, const char *dest, const char *fstype,
 
 	ret = mount(mntsrc, destbuf, fstype, flags, mnt_opts);
 	saved_errno = errno;
-	if (ret < 0 && strcmp(fstype, "mqueue") == 0) {
+	if (ret < 0 && fstype != NULL && strcmp(fstype, "mqueue") == 0) {
 		INFO("older kernels don't support labeling of /dev/mqueue, retry without selinux context");
 		ret = mount(mntsrc, destbuf, fstype, flags, data);
 		saved_errno = errno;
@@ -1250,12 +1250,13 @@ int safe_mount(const char *src, const char *dest, const char *fstype,
 	}
 
 #ifdef HAVE_ISULAD
-	if (strcmp(fstype, "mqueue") == 0 && lsm_file_label_set(dest, mount_label) != 0) {
+	if (fstype != NULL && strcmp(fstype, "mqueue") == 0 && lsm_file_label_set(dest, mount_label) != 0) {
 		ERROR("Failed to set file label on %s", dest);
 		return -EINVAL;
 	}
 
-	if (strcmp(fstype, "bind") == 0 && relabel_bind_mount_source(src, fstype, (const char *)data, mount_label) != 0) {
+	if (fstype != NULL && strcmp(fstype, "bind") == 0 &&
+		    relabel_bind_mount_source(src, fstype, (const char *)data, mount_label) != 0) {
 		ERROR("Failed to reabel %s with %s", src, mount_label);
 		return -EINVAL;
 	}
-- 
2.25.1

