90 lines
3.0 KiB
Diff
90 lines
3.0 KiB
Diff
From d5698095b50813afa2a0c0063c8a7c3df142bac9 Mon Sep 17 00:00:00 2001
|
|
From: wujing <wujing50@huawei.com>
|
|
Date: Wed, 24 Jun 2020 12:07:39 +0800
|
|
Subject: [PATCH 5/6] fix label-file reading bug
|
|
|
|
Signed-off-by: wujing <wujing50@huawei.com>
|
|
---
|
|
src/cmd/isula/base/create.c | 11 +++--------
|
|
src/services/execution/spec/selinux_label.c | 6 +-----
|
|
2 files changed, 4 insertions(+), 13 deletions(-)
|
|
|
|
diff --git a/src/cmd/isula/base/create.c b/src/cmd/isula/base/create.c
|
|
index 6fbc294e..148eea16 100644
|
|
--- a/src/cmd/isula/base/create.c
|
|
+++ b/src/cmd/isula/base/create.c
|
|
@@ -26,6 +26,7 @@
|
|
#include "arguments.h"
|
|
#include "isula_libutils/log.h"
|
|
#include "utils.h"
|
|
+#include "utils_string.h"
|
|
#include "console.h"
|
|
#include "create.h"
|
|
#include "commands.h"
|
|
@@ -433,7 +434,6 @@ static int read_label_from_file(const char *path, size_t file_size, isula_contai
|
|
FILE *fp = NULL;
|
|
char *buf = NULL;
|
|
size_t len;
|
|
- ssize_t num;
|
|
|
|
if (file_size == 0) {
|
|
return 0;
|
|
@@ -444,14 +444,10 @@ static int read_label_from_file(const char *path, size_t file_size, isula_contai
|
|
return -1;
|
|
}
|
|
__fsetlocking(fp, FSETLOCKING_BYCALLER);
|
|
- num = getline(&buf, &len, fp);
|
|
- while (num != -1) {
|
|
- size_t len = strlen(buf);
|
|
- if (len == 1) {
|
|
- num = getline(&buf, &len, fp);
|
|
+ while (getline(&buf, &len, fp) != -1) {
|
|
+ if (strlen(util_trim_space(buf)) == 0) {
|
|
continue;
|
|
}
|
|
- buf[len - 1] = '\0';
|
|
if (!validate_label(buf)) {
|
|
COMMAND_ERROR("Invalid label '%s': empty name", buf);
|
|
ret = -1;
|
|
@@ -462,7 +458,6 @@ static int read_label_from_file(const char *path, size_t file_size, isula_contai
|
|
ret = -1;
|
|
goto out;
|
|
}
|
|
- num = getline(&buf, &len, fp);
|
|
}
|
|
|
|
out:
|
|
diff --git a/src/services/execution/spec/selinux_label.c b/src/services/execution/spec/selinux_label.c
|
|
index 203ee29c..5732880f 100644
|
|
--- a/src/services/execution/spec/selinux_label.c
|
|
+++ b/src/services/execution/spec/selinux_label.c
|
|
@@ -125,7 +125,6 @@ static void find_selinux_fs_among_mounts(char **fs)
|
|
char *buf = NULL;
|
|
char **fields = NULL;
|
|
size_t len;
|
|
- ssize_t num;
|
|
|
|
fp = fopen("/proc/self/mountinfo", "re");
|
|
if (fp == NULL) {
|
|
@@ -134,16 +133,13 @@ static void find_selinux_fs_among_mounts(char **fs)
|
|
}
|
|
__fsetlocking(fp, FSETLOCKING_BYCALLER);
|
|
|
|
- num = getline(&buf, &len, fp);
|
|
- while (num != -1) {
|
|
+ while (getline(&buf, &len, fp) != -1) {
|
|
if (!strstr(buf, " - selinuxfs ")) {
|
|
- num = getline(&buf, &len, fp);
|
|
continue;
|
|
}
|
|
fields = util_string_split((const char *)buf, ' ');
|
|
if (fields == NULL || util_array_len((const char **)fields) < MOUNT_POOINT_FIFTH_FIELD + 1) {
|
|
util_free_array(fields);
|
|
- num = getline(&buf, &len, fp);
|
|
continue;
|
|
}
|
|
if (verify_selinuxfs_mount(fields[MOUNT_POOINT_FIFTH_FIELD - 1])) {
|
|
--
|
|
2.25.1
|
|
|