From f60fbbd3e3b5835515ec02a3c7711ed76d61dc7e Mon Sep 17 00:00:00 2001 From: haozi007 Date: Mon, 16 May 2022 03:50:05 +0100 Subject: [PATCH] sync from upstream openEuler/iSulad Signed-off-by: haozi007 --- 0001-cleancode-http-request.patch | 4 +- ...-refactor-mount-parse-in-spec-module.patch | 4 +- ...sula-wait-even-if-it-s-not-oci-image.patch | 4 +- 0004-add-isula-import-restful-mode.patch | 4 +- ...libc-parser-for-passwd-and-group-obj.patch | 5 +- ...the-enabled-selinux-host-environment.patch | 111 ++++ ...to-bionic-libc-improve-lcov-coverage.patch | 6 +- ...-isulad-shim-module-encoding-problem.patch | 87 +++ 0009-fix-utils-module-encoding-problem.patch | 521 ++++++++++++++++++ 0010-clean-the-gRPC-client-module-code.patch | 226 ++++++++ 0011-remove-redundant-code.patch | 238 ++++++++ ...oding-irregularities-of-entry-module.patch | 501 +++++++++++++++++ 0013-fix-coding-irregularities.patch | 187 +++++++ 0014-fix-ut-bug-and-arguments-check.patch | 275 +++++++++ ...-util_getgrent_r-and-util_getpwent_r.patch | 408 ++++++++++++++ 0016-add-check-result-argument-ut.patch | 33 ++ iSulad.spec | 24 +- 17 files changed, 2621 insertions(+), 17 deletions(-) create mode 100644 0006-test-adapt-to-the-enabled-selinux-host-environment.patch rename 0006-Adapt-to-bionic-libc-improve-lcov-coverage.patch => 0007-Adapt-to-bionic-libc-improve-lcov-coverage.patch (95%) create mode 100644 0008-fix-cmd-isulad-shim-module-encoding-problem.patch create mode 100644 0009-fix-utils-module-encoding-problem.patch create mode 100644 0010-clean-the-gRPC-client-module-code.patch create mode 100644 0011-remove-redundant-code.patch create mode 100644 0012-fix-coding-irregularities-of-entry-module.patch create mode 100644 0013-fix-coding-irregularities.patch create mode 100644 0014-fix-ut-bug-and-arguments-check.patch create mode 100644 0015-refactor-util_getgrent_r-and-util_getpwent_r.patch create mode 100644 0016-add-check-result-argument-ut.patch diff --git a/0001-cleancode-http-request.patch b/0001-cleancode-http-request.patch index 9ccffc8..5cf7958 100644 --- a/0001-cleancode-http-request.patch +++ b/0001-cleancode-http-request.patch @@ -1,7 +1,7 @@ From c0900d0bb68cb29484f670a67412447df316ff6e Mon Sep 17 00:00:00 2001 From: zhangxiaoyu Date: Tue, 19 Apr 2022 18:33:16 +0800 -Subject: [PATCH 1/5] cleancode: http request +Subject: [PATCH 01/16] cleancode: http request Signed-off-by: zhangxiaoyu --- @@ -207,5 +207,5 @@ index 2ed7fbe8..0b53cf1e 100644 static void close_file(FILE *pagefile) -- -2.32.0 (Apple Git-132) +2.20.1 diff --git a/0002-refactor-mount-parse-in-spec-module.patch b/0002-refactor-mount-parse-in-spec-module.patch index 28c0225..ce4fc98 100644 --- a/0002-refactor-mount-parse-in-spec-module.patch +++ b/0002-refactor-mount-parse-in-spec-module.patch @@ -1,7 +1,7 @@ From b58453982016f9a2f707b51ad54f12583aa21929 Mon Sep 17 00:00:00 2001 From: wujing Date: Wed, 20 Apr 2022 10:52:30 +0800 -Subject: [PATCH 2/5] refactor mount parse in spec module +Subject: [PATCH 02/16] refactor mount parse in spec module Signed-off-by: wujing --- @@ -231,5 +231,5 @@ index 5644b21e..c89f077f 100644 if (tmpfs == NULL) { return NULL; -- -2.32.0 (Apple Git-132) +2.20.1 diff --git a/0003-support-isula-wait-even-if-it-s-not-oci-image.patch b/0003-support-isula-wait-even-if-it-s-not-oci-image.patch index 7c3a530..f38ae9b 100644 --- a/0003-support-isula-wait-even-if-it-s-not-oci-image.patch +++ b/0003-support-isula-wait-even-if-it-s-not-oci-image.patch @@ -1,7 +1,7 @@ From e0c13b23ddee161a6196ca2e0c970704e4bbef0e Mon Sep 17 00:00:00 2001 From: WangFengTu Date: Sun, 24 Apr 2022 14:18:26 +0800 -Subject: [PATCH 3/5] support isula wait even if it's not oci image +Subject: [PATCH 03/16] support isula wait even if it's not oci image Signed-off-by: WangFengTu --- @@ -26,5 +26,5 @@ index 0e5b845c..2deb862c 100644 // `logs` sub-command "logs", false, cmd_logs_main, g_cmd_logs_desc, NULL, &g_cmd_logs_args -- -2.32.0 (Apple Git-132) +2.20.1 diff --git a/0004-add-isula-import-restful-mode.patch b/0004-add-isula-import-restful-mode.patch index eeb6166..4b7d2e8 100644 --- a/0004-add-isula-import-restful-mode.patch +++ b/0004-add-isula-import-restful-mode.patch @@ -1,7 +1,7 @@ From 0f05484cceb58117f165bcc402156194289ea9c3 Mon Sep 17 00:00:00 2001 From: chengzrz Date: Thu, 28 Apr 2022 19:11:46 +0800 -Subject: [PATCH 4/5] add isula import restful mode +Subject: [PATCH 04/16] add isula import restful mode Signed-off-by: chengzrz --- @@ -263,5 +263,5 @@ index 39a3bd6c..7107d255 100644 return 0; } -- -2.32.0 (Apple Git-132) +2.20.1 diff --git a/0005-Adapt-to-bionic-libc-parser-for-passwd-and-group-obj.patch b/0005-Adapt-to-bionic-libc-parser-for-passwd-and-group-obj.patch index ad6d308..8839ac8 100644 --- a/0005-Adapt-to-bionic-libc-parser-for-passwd-and-group-obj.patch +++ b/0005-Adapt-to-bionic-libc-parser-for-passwd-and-group-obj.patch @@ -1,7 +1,8 @@ From 1d768559f42375eb3bbb3ad0de52a6b49535e40c Mon Sep 17 00:00:00 2001 From: chegJH Date: Thu, 7 Apr 2022 17:33:06 +0800 -Subject: [PATCH 5/5] Adapt to bionic libc, parser for passwd and group object +Subject: [PATCH 05/16] Adapt to bionic libc, parser for passwd and group + object Signed-off-by: chegJH --- @@ -653,5 +654,5 @@ index 00000000..1a121f88 +} \ No newline at end of file -- -2.32.0 (Apple Git-132) +2.20.1 diff --git a/0006-test-adapt-to-the-enabled-selinux-host-environment.patch b/0006-test-adapt-to-the-enabled-selinux-host-environment.patch new file mode 100644 index 0000000..e0331ad --- /dev/null +++ b/0006-test-adapt-to-the-enabled-selinux-host-environment.patch @@ -0,0 +1,111 @@ +From a5c3e6064b583477de8564a20799a630474d556d Mon Sep 17 00:00:00 2001 +From: wujing +Date: Tue, 29 Mar 2022 20:07:31 +0800 +Subject: [PATCH 06/16] test: adapt to the enabled selinux host environment + +Signed-off-by: wujing +--- + test/services/execution/spec/CMakeLists.txt | 2 + + .../execution/spec/selinux_label_ut.cc | 48 ++++++++++++++++--- + 2 files changed, 43 insertions(+), 7 deletions(-) + +diff --git a/test/services/execution/spec/CMakeLists.txt b/test/services/execution/spec/CMakeLists.txt +index 9ce30219..e1aa680e 100644 +--- a/test/services/execution/spec/CMakeLists.txt ++++ b/test/services/execution/spec/CMakeLists.txt +@@ -15,6 +15,7 @@ add_executable(${EXE} + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/utils/cutils/path.c + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/utils/cutils/map/map.c + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/utils/cutils/map/rb_tree.c ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/utils/cpputils/cxxutils.cc + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon/common/err_msg.c + ${CMAKE_CURRENT_SOURCE_DIR}/../../../mocks/namespace_mock.cc + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon/common/selinux_label.c +@@ -46,6 +47,7 @@ target_include_directories(${EXE} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon/common + ${CMAKE_CURRENT_SOURCE_DIR}/../../../include + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/utils/cutils ++ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/utils/cpputils + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/utils/sha256 + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/utils/cutils/map + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon/services/execution/manager +diff --git a/test/services/execution/spec/selinux_label_ut.cc b/test/services/execution/spec/selinux_label_ut.cc +index ea3c480c..c0e9ab1c 100644 +--- a/test/services/execution/spec/selinux_label_ut.cc ++++ b/test/services/execution/spec/selinux_label_ut.cc +@@ -25,6 +25,7 @@ + #include + #include "namespace_mock.h" + #include "utils.h" ++#include "cxxutils.h" + + using namespace std; + +@@ -40,6 +41,34 @@ protected: + } + }; + ++std::string get_lxc_context_filed(const std::string &filed) ++{ ++ ifstream in("/etc/selinux/targeted/contexts/lxc_contexts"); ++ string line; ++ while (getline(in, line)) { ++ stringstream ss(line); ++ string tmp; ++ while (getline(ss, tmp)) { ++ auto configs = CXXUtils::Split(tmp, '='); ++ if (configs.size() != 2) { ++ return ""; ++ } ++ if (configs.at(0).substr(0, filed.size()) != filed) { ++ continue; ++ } ++ ++ auto elements = CXXUtils::Split(configs.at(1), ':'); ++ if (elements.size() < 3) { ++ return ""; ++ } ++ ++ return elements.at(2); ++ } ++ } ++ ++ return ""; ++} ++ + TEST_F(SELinuxLabelUnitTest, test_init_label_normal) + { + const char *disable_label[] = { "disable" }; +@@ -48,17 +77,22 @@ TEST_F(SELinuxLabelUnitTest, test_init_label_normal) + const char *type_label[] = { "type:faketype" }; + const char *level_label[] = { "level:s0:c1,c2" }; + const char *full_label[] = { "user:fakeuser", "level:s0:c1,c2", "type:faketype", "role:fakerole" }; ++ std::string process_context = get_lxc_context_filed("process"); ++ std::string file_context = get_lxc_context_filed("file"); + + std::vector> normal { + std::make_tuple(disable_label, 1, 0, "", ""), +- std::make_tuple(user_label, 1, 0, "fakeuser:system_r:container_t:s0", "fakeuser:object_r:container_file_t:s0"), +- std::make_tuple(role_label, 1, 0, "system_u:fakerole:container_t:s0", "system_u:object_r:container_file_t:s0"), +- std::make_tuple(type_label, 1, 0, "system_u:system_r:faketype:s0", "system_u:object_r:container_file_t:s0"), +- std::make_tuple(level_label, 1, 0, "system_u:system_r:container_t:s0:c1,c2", +- "system_u:object_r:container_file_t:s0:c1,c2"), ++ std::make_tuple(user_label, 1, 0, "fakeuser:system_r:" + process_context + ":s0", ++ "fakeuser:object_r:" + file_context + ":s0"), ++ std::make_tuple(role_label, 1, 0, "system_u:fakerole:" + process_context + ":s0", ++ "system_u:object_r:" + file_context + ":s0"), ++ std::make_tuple(type_label, 1, 0, "system_u:system_r:faketype:s0", "system_u:object_r:" + file_context + ":s0"), ++ std::make_tuple(level_label, 1, 0, "system_u:system_r:" + process_context + ":s0:c1,c2", ++ "system_u:object_r:" + file_context + ":s0:c1,c2"), + std::make_tuple(full_label, 4, 0, "fakeuser:fakerole:faketype:s0:c1,c2", +- "fakeuser:object_r:container_file_t:s0:c1,c2"), +- std::make_tuple(nullptr, 0, 0, "system_u:system_r:container_t:s0", "system_u:object_r:container_file_t:s0"), ++ "fakeuser:object_r:" + file_context + ":s0:c1,c2"), ++ std::make_tuple(nullptr, 0, 0, "system_u:system_r:" + process_context + ":s0", ++ "system_u:object_r:" + file_context + ":s0"), + }; + + if (!is_selinux_enabled()) { +-- +2.20.1 + diff --git a/0006-Adapt-to-bionic-libc-improve-lcov-coverage.patch b/0007-Adapt-to-bionic-libc-improve-lcov-coverage.patch similarity index 95% rename from 0006-Adapt-to-bionic-libc-improve-lcov-coverage.patch rename to 0007-Adapt-to-bionic-libc-improve-lcov-coverage.patch index 8626af6..2c5b751 100644 --- a/0006-Adapt-to-bionic-libc-improve-lcov-coverage.patch +++ b/0007-Adapt-to-bionic-libc-improve-lcov-coverage.patch @@ -1,7 +1,7 @@ -From 88596185a48394d9aea122e80a6b6cf86ac216ba Mon Sep 17 00:00:00 2001 +From ef8bec5f8c3d7b60d2d5148f3386f00c3a29ffc2 Mon Sep 17 00:00:00 2001 From: chegJH Date: Tue, 10 May 2022 18:06:53 +0800 -Subject: [PATCH] Adapt to bionic libc, improve lcov coverage +Subject: [PATCH 07/16] Adapt to bionic libc, improve lcov coverage Signed-off-by: chegJH --- @@ -94,5 +94,5 @@ index 1a121f88..1ed8eaa1 100644 ASSERT_EQ(util_getgrent_r(f_gr, &gr, buf, sizeof(buf), &pgr), 0); ASSERT_STREQ(gr.gr_name, std::get<0>(testcase[i]).c_str()); -- -2.32.0 (Apple Git-132) +2.20.1 diff --git a/0008-fix-cmd-isulad-shim-module-encoding-problem.patch b/0008-fix-cmd-isulad-shim-module-encoding-problem.patch new file mode 100644 index 0000000..53c28fc --- /dev/null +++ b/0008-fix-cmd-isulad-shim-module-encoding-problem.patch @@ -0,0 +1,87 @@ +From 16bfb6e4a4deb5164f8644de3b76129e428653c7 Mon Sep 17 00:00:00 2001 +From: wujing +Date: Mon, 17 Jan 2022 11:24:05 +0800 +Subject: [PATCH 08/16] fix cmd/isulad-shim module encoding problem + +Signed-off-by: wujing +--- + src/cmd/isulad-shim/common.c | 2 -- + src/cmd/isulad-shim/common.h | 17 ++++++++--------- + src/cmd/isulad-shim/process.c | 4 +--- + 3 files changed, 9 insertions(+), 14 deletions(-) + +diff --git a/src/cmd/isulad-shim/common.c b/src/cmd/isulad-shim/common.c +index 324d72a1..20e0963c 100644 +--- a/src/cmd/isulad-shim/common.c ++++ b/src/cmd/isulad-shim/common.c +@@ -236,8 +236,6 @@ void write_message(int fd, const char *level, const char *fmt, ...) + if (nwrite != strlen(msg)) { + return; + } +- +- return; + } + + /* note: This function can only read small text file. */ +diff --git a/src/cmd/isulad-shim/common.h b/src/cmd/isulad-shim/common.h +index 8c6ea7ba..d06c5256 100644 +--- a/src/cmd/isulad-shim/common.h ++++ b/src/cmd/isulad-shim/common.h +@@ -26,19 +26,19 @@ extern "C" { + + // error code + #define SHIM_ERR_BASE (-10000) +-#define SHIM_SYS_ERR(err) (SHIM_ERR_BASE-err) +-#define SHIM_OK 0 +-#define SHIM_ERR -1 +-#define SHIM_ERR_WAIT -2 +-#define SHIM_ERR_NOT_REQUIRED -3 ++#define SHIM_SYS_ERR(err) (SHIM_ERR_BASE - err) ++#define SHIM_OK 0 ++#define SHIM_ERR (-1) ++#define SHIM_ERR_WAIT (-2) ++#define SHIM_ERR_NOT_REQUIRED (-3) + + #define INFO_MSG "info" + #define WARN_MSG "warn" + #define ERR_MSG "error" + +-#define DEFAULT_TIMEOUT 120 // sec +-#define CONTAINER_ID_LEN 64 +-#define MAX_RT_NAME_LEN 64 ++#define DEFAULT_TIMEOUT 120 // sec ++#define CONTAINER_ID_LEN 64 ++#define MAX_RT_NAME_LEN 64 + #define MAX_CONSOLE_SOCK_LEN 32 + + #define MAX_RUNTIME_ARGS 20 +@@ -73,4 +73,3 @@ int open_no_inherit(const char *path, int flag, mode_t mode); + #endif + + #endif +- +diff --git a/src/cmd/isulad-shim/process.c b/src/cmd/isulad-shim/process.c +index b3014d7a..21b2523a 100644 +--- a/src/cmd/isulad-shim/process.c ++++ b/src/cmd/isulad-shim/process.c +@@ -351,8 +351,6 @@ static void sem_post_inotify_io_copy(int fd, uint32_t event, void *data) + thd->shutdown = true; + (void)sem_post(&thd->sem_thd); + } +- +- return; + } + + static int create_io_copy_thread(process_t *p, int std_id) +@@ -1029,7 +1027,7 @@ static void process_delete(process_t *p) + int i = 0; + int j; + char log_path[PATH_MAX] = { 0 }; +- char *cwd; ++ char *cwd = NULL; + + cwd = getcwd(NULL, 0); + if (cwd == NULL) { +-- +2.20.1 + diff --git a/0009-fix-utils-module-encoding-problem.patch b/0009-fix-utils-module-encoding-problem.patch new file mode 100644 index 0000000..5d5ae8a --- /dev/null +++ b/0009-fix-utils-module-encoding-problem.patch @@ -0,0 +1,521 @@ +From dff4e8fc306e2270695c20434f79bcf3303c8f37 Mon Sep 17 00:00:00 2001 +From: wujing +Date: Tue, 18 Jan 2022 17:21:15 +0800 +Subject: [PATCH 09/16] fix utils module encoding problem + +Signed-off-by: wujing +--- + src/utils/console/console.c | 2 +- + src/utils/console/console.h | 4 +- + src/utils/cpputils/stoppable_thread.cc | 7 +-- + src/utils/cpputils/stoppable_thread.h | 15 ++++--- + src/utils/cpputils/url.cc | 61 ++++++++++++-------------- + src/utils/cutils/utils_aes.c | 4 +- + src/utils/cutils/utils_mount_spec.c | 41 ++++++++--------- + src/utils/cutils/utils_string.c | 4 +- + src/utils/cutils/utils_timestamp.c | 11 +++-- + 9 files changed, 73 insertions(+), 76 deletions(-) + +diff --git a/src/utils/console/console.c b/src/utils/console/console.c +index b1d8b6dc..17c8b242 100644 +--- a/src/utils/console/console.c ++++ b/src/utils/console/console.c +@@ -437,7 +437,7 @@ err_out: + + /* console loop copy */ + int console_loop_io_copy(int sync_fd, const int *srcfds, struct io_write_wrapper *writers, +- transfer_channel_type *channels, size_t len) ++ const transfer_channel_type *channels, size_t len) + { + int ret = 0; + size_t i = 0; +diff --git a/src/utils/console/console.h b/src/utils/console/console.h +index 63103d2b..f42ec994 100644 +--- a/src/utils/console/console.h ++++ b/src/utils/console/console.h +@@ -43,7 +43,7 @@ struct tty_state { + bool ignore_stdin_close; + }; + +-typedef enum { STDIN_CHANNEL, STDOUT_CHANNEL, STDERR_CHANNEL, MAX_CHANNEL} transfer_channel_type; ++typedef enum { STDIN_CHANNEL, STDOUT_CHANNEL, STDERR_CHANNEL, MAX_CHANNEL } transfer_channel_type; + + int console_fifo_name(const char *rundir, const char *subpath, const char *stdflag, char *fifo_name, + size_t fifo_name_sz, char *fifo_path, size_t fifo_path_sz, bool do_mkdirp); +@@ -62,7 +62,7 @@ int console_loop_with_std_fd(int stdinfd, int stdoutfd, int stderrfd, int fifoin + int tty_exit, bool tty); + + int console_loop_io_copy(int sync_fd, const int *srcfds, struct io_write_wrapper *writers, +- transfer_channel_type *channels, size_t len); ++ const transfer_channel_type *channels, size_t len); + + int setup_tios(int fd, struct termios *curr_tios); + +diff --git a/src/utils/cpputils/stoppable_thread.cc b/src/utils/cpputils/stoppable_thread.cc +index 68f6d9b2..20c6b374 100644 +--- a/src/utils/cpputils/stoppable_thread.cc ++++ b/src/utils/cpputils/stoppable_thread.cc +@@ -15,7 +15,7 @@ + + #include "stoppable_thread.h" + +-StoppableThread &StoppableThread::operator=(StoppableThread &&obj) ++StoppableThread &StoppableThread::operator=(StoppableThread &&obj) noexcept + { + m_exit_signal = std::move(obj.m_exit_signal); + m_future_obj = std::move(obj.m_future_obj); +@@ -24,10 +24,7 @@ StoppableThread &StoppableThread::operator=(StoppableThread &&obj) + + bool StoppableThread::stopRequested() + { +- if (m_future_obj.wait_for(std::chrono::milliseconds(0)) == std::future_status::timeout) { +- return false; +- } +- return true; ++ return m_future_obj.wait_for(std::chrono::milliseconds(0)) != std::future_status::timeout; + } + + void StoppableThread::stop() +diff --git a/src/utils/cpputils/stoppable_thread.h b/src/utils/cpputils/stoppable_thread.h +index 7dfd61f9..f5f4fb3f 100644 +--- a/src/utils/cpputils/stoppable_thread.h ++++ b/src/utils/cpputils/stoppable_thread.h +@@ -23,12 +23,18 @@ + + class StoppableThread { + public: +- StoppableThread() : m_future_obj(m_exit_signal.get_future()) {} ++ StoppableThread() ++ : m_future_obj(m_exit_signal.get_future()) ++ { ++ } + +- explicit StoppableThread(StoppableThread &&obj) : m_exit_signal(std::move(obj.m_exit_signal)), +- m_future_obj(std::move(obj.m_future_obj)) {} ++ explicit StoppableThread(StoppableThread &&obj) noexcept ++ : m_exit_signal(std::move(obj.m_exit_signal)) ++ , m_future_obj(std::move(obj.m_future_obj)) ++ { ++ } + +- StoppableThread &operator=(StoppableThread &&obj); ++ StoppableThread &operator=(StoppableThread &&obj) noexcept; + + virtual ~StoppableThread() = default; + +@@ -49,4 +55,3 @@ private: + }; + + #endif // UTILS_CPPUTILS_STOPPABLE_THREAD_H +- +diff --git a/src/utils/cpputils/url.cc b/src/utils/cpputils/url.cc +index 39032feb..ab1355a3 100644 +--- a/src/utils/cpputils/url.cc ++++ b/src/utils/cpputils/url.cc +@@ -109,7 +109,7 @@ int UnescapeDealWithPercentSign(size_t &i, std::string &s, const EncodeMode &mod + if (s.length() > 3) { + s.erase(s.begin() + 3, s.end()); + } +- ERROR("invalid URL escape %s", s.c_str()); // quoted ++ ERROR("invalid URL escape %s", s.c_str()); // quoted + return -1; + } + char s1, s2; +@@ -123,10 +123,10 @@ int UnescapeDealWithPercentSign(size_t &i, std::string &s, const EncodeMode &mod + } + if (mode == EncodeMode::ENCODE_ZONE) { + char v = static_cast((static_cast(s1) << 4) | static_cast(s2)); +- if (std::string(s.begin() + static_cast(i), s.begin() + static_cast(i) + 3) != "%25" && +- v != ' ' && ShouldEscape(v, EncodeMode::ENCODE_HOST)) { +- ERROR("invalid URL escape %s", std::string(s.begin() + static_cast(i), +- s.begin() + static_cast(i) + 3).c_str()); ++ if (std::string(s.begin() + static_cast(i), s.begin() + static_cast(i) + 3) != "%25" && v != ' ' && ++ ShouldEscape(v, EncodeMode::ENCODE_HOST)) { ++ ERROR("invalid URL escape %s", ++ std::string(s.begin() + static_cast(i), s.begin() + static_cast(i) + 3).c_str()); + return -1; + } + } +@@ -153,8 +153,8 @@ int CalculatePercentNum(std::string &s, const EncodeMode &mode, bool &hasPlus) + } + break; + default: +- if ((mode == EncodeMode::ENCODE_HOST || mode == EncodeMode::ENCODE_ZONE) && +- int(s[i]) < 0x80 && ShouldEscape(s[i], mode)) { ++ if ((mode == EncodeMode::ENCODE_HOST || mode == EncodeMode::ENCODE_ZONE) && int(s[i]) < 0x80 && ++ ShouldEscape(s[i], mode)) { + ERROR("invalid URL escape %s", std::string(s.begin() + (long)i, s.begin() + (long)i + 1).c_str()); + return -1; + } +@@ -319,7 +319,7 @@ URLDatum *Parse(const std::string &rawurl) + { + std::string u, frag; + Split(rawurl, "#", true, u, frag); +- auto url = Parse(u, false); ++ auto *url = Parse(u, false); + if (url == nullptr) { + return nullptr; + } +@@ -335,12 +335,11 @@ URLDatum *Parse(const std::string &rawurl) + + int SplitOffPossibleLeading(std::string &scheme, const std::string &rawurl, URLDatum *url, std::string &rest) + { +- if (Getscheme(rawurl, scheme, rest)) { ++ if (Getscheme(rawurl, scheme, rest) != 0) { + return -1; + } + std::transform(scheme.begin(), scheme.end(), scheme.begin(), ::tolower); +- if (rest.at(rest.length() - 1) == '?' && +- std::count(rest.begin(), rest.end(), '?') == 1) { ++ if (rest.at(rest.length() - 1) == '?' && std::count(rest.begin(), rest.end(), '?') == 1) { + url->SetForceQuery(true); + rest = rest.substr(0, rest.length() - 1); + } else { +@@ -351,8 +350,8 @@ int SplitOffPossibleLeading(std::string &scheme, const std::string &rawurl, URLD + return 0; + } + +-URLDatum *HandleNonBackslashPrefix(URLDatum *url, const std::string &scheme, +- const std::string &rest, bool viaRequest, bool &should_ret) ++URLDatum *HandleNonBackslashPrefix(URLDatum *url, const std::string &scheme, const std::string &rest, bool viaRequest, ++ bool &should_ret) + { + if (rest.at(0) == '/') { + return nullptr; +@@ -403,7 +402,7 @@ URLDatum *Parse(const std::string &rawurl, bool viaRequest) + ERROR("empty url!"); + return nullptr; + } +- URLDatum *url = new (std::nothrow) URLDatum; ++ auto *url = new (std::nothrow) URLDatum; + if (url == nullptr) { + ERROR("Out of memory"); + return nullptr; +@@ -414,15 +413,15 @@ URLDatum *Parse(const std::string &rawurl, bool viaRequest) + } + std::string scheme = url->GetScheme(); + std::string rest; +- if (SplitOffPossibleLeading(scheme, rawurl, url, rest)) { ++ if (SplitOffPossibleLeading(scheme, rawurl, url, rest) != 0) { + return nullptr; + } + bool should_ret = false; +- auto tmpret = HandleNonBackslashPrefix(url, scheme, rest, viaRequest, should_ret); ++ auto *tmpret = HandleNonBackslashPrefix(url, scheme, rest, viaRequest, should_ret); + if (should_ret) { + return tmpret; + } +- if (SetURLDatumInfo(url, scheme, viaRequest, rest)) { ++ if (SetURLDatumInfo(url, scheme, viaRequest, rest) != 0) { + return nullptr; + } + return url; +@@ -432,13 +431,13 @@ int ParseAuthority(const std::string &authority, UserInfo **user, std::string &h + { + size_t i = authority.find("@"); + if (i == std::string::npos) { +- if (ParseHost(authority, host)) { ++ if (ParseHost(authority, host) != 0) { + *user = nullptr; + host = ""; + return -1; + } + } else { +- if (ParseHost(authority.substr(i + 1, authority.size()), host)) { ++ if (ParseHost(authority.substr(i + 1, authority.size()), host) != 0) { + *user = nullptr; + host = ""; + return -1; +@@ -602,7 +601,7 @@ std::string GetFullPreResolvePath(const std::string &base, const std::string &re + void SplitFullPreResolvePath(const std::string &full, std::vector &dst) + { + std::vector src = CXXUtils::Split(full, '/'); +- for (auto elem : src) { ++ for (const auto &elem : src) { + if (elem == ".") { + continue; + } else if (elem == "..") { +@@ -676,8 +675,8 @@ bool ValidUserinfo(const std::string &s) + { + std::string subDelims = R"(-._:~!$&'()*+,;=%@)"; + for (const auto &r : s) { +- if (('A' <= r && r <= 'Z') || ('a' <= r && r <= 'z') || +- ('0' <= r && r <= '9') || (subDelims.find(r) != std::string::npos)) { ++ if (('A' <= r && r <= 'Z') || ('a' <= r && r <= 'z') || ('0' <= r && r <= '9') || ++ (subDelims.find(r) != std::string::npos)) { + continue; + } + return false; +@@ -687,11 +686,11 @@ bool ValidUserinfo(const std::string &s) + + std::string Values::Get(const std::string &key) + { +- if (v.size() == 0) { ++ if (v.empty()) { + return ""; + } + std::vector vs = v[key]; +- if (vs.size() == 0) { ++ if (vs.empty()) { + return ""; + } + return vs[0]; +@@ -731,7 +730,7 @@ std::string Values::Encode() + for (auto k : keys) { + std::vector vs = v[k]; + std::string keyEscaped = QueryEscape(k); +- for (auto elem : vs) { ++ for (const auto &elem : vs) { + if (buf.length() > 0) { + buf.append("&"); + } +@@ -817,8 +816,7 @@ void URLDatum::StringOpaqueEmptyRules(std::string &buf) + } + if (buf.length() == 0) { + auto i = m_path.find(":"); +- if (i != std::string::npos && +- path.substr(0, i).find("/") == std::string::npos) { ++ if (i != std::string::npos && path.substr(0, i).find("/") == std::string::npos) { + buf.append("./"); + } + } +@@ -855,7 +853,7 @@ bool URLDatum::IsAbs() const + + std::unique_ptr URLDatum::UrlParse(const std::string &ref) + { +- auto refurl = Parse(ref); ++ auto *refurl = Parse(ref); + if (refurl == nullptr) { + return nullptr; + } +@@ -894,8 +892,7 @@ std::unique_ptr URLDatum::ResolveReference(URLDatum *ref) + return url; + } + +- +-auto URLDatum::Query() ->std::map> ++auto URLDatum::Query() -> std::map> + { + return ParseQuery(m_rawQuery); + } +@@ -928,6 +925,4 @@ std::string URLDatum::Port() const + { + return PortOnly(m_host); + } +-} // namespace url +- +- ++} // namespace url +diff --git a/src/utils/cutils/utils_aes.c b/src/utils/cutils/utils_aes.c +index 1df95fd5..5dc822a2 100644 +--- a/src/utils/cutils/utils_aes.c ++++ b/src/utils/cutils/utils_aes.c +@@ -95,9 +95,9 @@ size_t util_aes_decode_buf_len(size_t len) + { + if (len % AES_BLOCK_SIZE == 0) { + return len; +- } else { +- return (len / AES_BLOCK_SIZE * AES_BLOCK_SIZE) + AES_BLOCK_SIZE; + } ++ ++ return (len / AES_BLOCK_SIZE * AES_BLOCK_SIZE) + AES_BLOCK_SIZE; + } + + size_t util_aes_encode_buf_len(size_t len) +diff --git a/src/utils/cutils/utils_mount_spec.c b/src/utils/cutils/utils_mount_spec.c +index a262a249..d8f64c81 100644 +--- a/src/utils/cutils/utils_mount_spec.c ++++ b/src/utils/cutils/utils_mount_spec.c +@@ -31,8 +31,8 @@ + #include "path.h" + + #define CACHE_ERRMSG_LEN 512 +-#define CACHE_ERRMSG(errmsg, fmt, args...) \ +- do { \ ++#define CACHE_ERRMSG(errmsg, fmt, args...) \ ++ do { \ + (void)snprintf(errmsg, CACHE_ERRMSG_LEN, fmt, ##args); \ + } while (0) + +@@ -49,8 +49,8 @@ static int parse_mount_item_type(const char *value, char *mount_str, mount_spec + } + + #ifdef ENABLE_OCI_IMAGE +- if (strcmp(value, MOUNT_TYPE_SQUASHFS) && strcmp(value, MOUNT_TYPE_BIND) && +- strcmp(value, MOUNT_TYPE_VOLUME) && strcmp(value, MOUNT_TYPE_TMPFS)) { ++ if (strcmp(value, MOUNT_TYPE_SQUASHFS) != 0 && strcmp(value, MOUNT_TYPE_BIND) != 0 && ++ strcmp(value, MOUNT_TYPE_VOLUME) != 0 && strcmp(value, MOUNT_TYPE_TMPFS) != 0) { + CACHE_ERRMSG(errmsg, "Invalid mount specification '%s'.Type must be one of squashfs/bind/volume/tmpfs", + mount_str); + #else +@@ -67,7 +67,7 @@ static int parse_mount_item_type(const char *value, char *mount_str, mount_spec + + static int parse_mount_item_src(const char *value, char *mount_str, mount_spec *m, char *errmsg) + { +- char srcpath[PATH_MAX] = {0}; ++ char srcpath[PATH_MAX] = { 0 }; + + /* If value of source is NULL, ignore it */ + if (value == NULL) { +@@ -88,7 +88,8 @@ static int parse_mount_item_src(const char *value, char *mount_str, mount_spec * + + if (value[0] == '/') { + if (!util_clean_path(value, srcpath, sizeof(srcpath))) { +- CACHE_ERRMSG(errmsg, "Invalid mount specification '%s'.Can't translate source path to clean path", mount_str); ++ CACHE_ERRMSG(errmsg, "Invalid mount specification '%s'.Can't translate source path to clean path", ++ mount_str); + return EINVALIDARGS; + } + m->source = util_strdup_s(srcpath); +@@ -119,7 +120,8 @@ static int parse_mount_item_dst(const char *value, char *mount_str, mount_spec * + } + + if (!util_clean_path(value, dstpath, sizeof(dstpath))) { +- CACHE_ERRMSG(errmsg, "Invalid mount specification '%s'.Can't translate destination path to clean path", mount_str); ++ CACHE_ERRMSG(errmsg, "Invalid mount specification '%s'.Can't translate destination path to clean path", ++ mount_str); + return EINVALIDARGS; + } + +@@ -306,7 +308,7 @@ static int parse_mount_item_nocopy(const char *value, char *mount_str, mount_spe + + static bool exist_readonly_mode(char *mount_str) + { +- char tmp_mount_str[PATH_MAX] = {0}; ++ char tmp_mount_str[PATH_MAX] = { 0 }; + int sret = 0; + + // add "," at start and end of mount string to simplize check +@@ -332,25 +334,26 @@ static bool valid_mount_spec_mode(char *mount_str, mount_spec *m, char *errmsg) + return false; + } + if (exist_readonly_mode(mount_str) && m->source == NULL) { +- CACHE_ERRMSG(errmsg, "Invalid mount specification '%s'.Readonly mode must not be specified " +- "for anonymous volume", mount_str); ++ CACHE_ERRMSG(errmsg, ++ "Invalid mount specification '%s'.Readonly mode must not be specified for anonymous volume", ++ mount_str); + return false; + } + } + if (strcmp(m->type, MOUNT_TYPE_BIND) == 0 && m->volume_options != NULL) { +- CACHE_ERRMSG(errmsg, "Invalid mount specification '%s'.nocopy must not be specified for type %s", +- mount_str, m->type); ++ CACHE_ERRMSG(errmsg, "Invalid mount specification '%s'.nocopy must not be specified for type %s", mount_str, ++ m->type); + return false; + } + if (strcmp(m->type, MOUNT_TYPE_TMPFS) == 0) { + if (m->volume_options != NULL) { +- CACHE_ERRMSG(errmsg, "Invalid mount specification '%s'.Cannot mix volume options with type %s", +- mount_str, m->type); ++ CACHE_ERRMSG(errmsg, "Invalid mount specification '%s'.Cannot mix volume options with type %s", mount_str, ++ m->type); + return false; + } + if (m->bind_options != NULL) { +- CACHE_ERRMSG(errmsg, "Invalid mount specification '%s'.Cannot mix bind options with type %s", +- mount_str, m->type); ++ CACHE_ERRMSG(errmsg, "Invalid mount specification '%s'.Cannot mix bind options with type %s", mount_str, ++ m->type); + return false; + } + } +@@ -415,7 +418,6 @@ static int check_mount_spec(char *mount_str, mount_spec *m, char *errmsg) + return 0; + } + +- + static int parse_mounts_item(const char *mntkey, const char *value, char *mount_str, mount_spec *m, char *errmsg) + { + if (util_valid_key_type(mntkey)) { +@@ -452,7 +454,7 @@ int util_parse_mount_spec(char *mount_str, mount_spec **spec, char **errmsg_out) + size_t items_len = 0; + char **items = NULL; + char **key_val = NULL; +- char errmsg[CACHE_ERRMSG_LEN] = {0}; ++ char errmsg[CACHE_ERRMSG_LEN] = { 0 }; + + if (mount_str == NULL) { + CACHE_ERRMSG(errmsg, "Invalid mount specification: can't be empty"); +@@ -528,7 +530,7 @@ bool util_valid_mount_spec(const char *mount_str, char **errmsg) + mount_spec *m = NULL; + + // if parse success, it's valid +- ret = util_parse_mount_spec((char*)mount_str, &m, errmsg); ++ ret = util_parse_mount_spec((char *)mount_str, &m, errmsg); + if (ret != 0) { + goto out; + } +@@ -538,4 +540,3 @@ out: + + return ret ? false : true; + } +- +diff --git a/src/utils/cutils/utils_string.c b/src/utils/cutils/utils_string.c +index 7e504326..8c9b2eea 100644 +--- a/src/utils/cutils/utils_string.c ++++ b/src/utils/cutils/utils_string.c +@@ -795,7 +795,7 @@ bool util_has_prefix(const char *str, const char *prefix) + return false; + } + +- if (strncmp(str, prefix, strlen(prefix))) { ++ if (strncmp(str, prefix, strlen(prefix)) != 0) { + return false; + } + +@@ -817,7 +817,7 @@ bool util_has_suffix(const char *str, const char *suffix) + return false; + } + +- if (strcmp(str + str_len - suffix_len, suffix)) { ++ if (strcmp(str + str_len - suffix_len, suffix) != 0) { + return false; + } + +diff --git a/src/utils/cutils/utils_timestamp.c b/src/utils/cutils/utils_timestamp.c +index 53ca7a95..ef695d3e 100644 +--- a/src/utils/cutils/utils_timestamp.c ++++ b/src/utils/cutils/utils_timestamp.c +@@ -189,8 +189,7 @@ bool get_time_buffer_help(const types_timestamp_t *timestamp, char *timebuffer, + if (tm_zone >= 0) { + nret = snprintf(timebuffer + strlen(timebuffer), tmp_size, ".%09d+%02d:00", nanos, tm_zone); + } else { +- nret = snprintf(timebuffer + strlen(timebuffer), tmp_size, ".%09d-%02d:00", nanos, +- -tm_zone); ++ nret = snprintf(timebuffer + strlen(timebuffer), tmp_size, ".%09d-%02d:00", nanos, -tm_zone); + } + + out: +@@ -524,7 +523,7 @@ static char *tm_get_zp(const char *tmstr) + return zp; + } + +-static inline bool hasnil(const char *str, struct tm *tm, int32_t *nanos, struct types_timezone *tz) ++static inline bool hasnil(const char *str, const struct tm *tm, const int32_t *nanos, const struct types_timezone *tz) + { + if (str == NULL || tm == NULL || nanos == NULL || tz == NULL) { + return true; +@@ -656,9 +655,9 @@ int64_t util_time_seconds_since(const char *in) + + if (result > 0) { + return result; +- } else { +- return 0; + } ++ ++ return 0; + } + + struct time_human_duration_rule_t { +@@ -1066,4 +1065,4 @@ int util_time_str_to_nanoseconds(const char *value, int64_t *nanoseconds) + out: + free(num_str); + return ret; +-} +\ No newline at end of file ++} +-- +2.20.1 + diff --git a/0010-clean-the-gRPC-client-module-code.patch b/0010-clean-the-gRPC-client-module-code.patch new file mode 100644 index 0000000..4814186 --- /dev/null +++ b/0010-clean-the-gRPC-client-module-code.patch @@ -0,0 +1,226 @@ +From 92ceff55c726abfabdc6e7f54d4e67b0c6c24196 Mon Sep 17 00:00:00 2001 +From: wujing +Date: Tue, 18 Jan 2022 19:59:39 +0800 +Subject: [PATCH 10/16] clean the gRPC client module code + +Signed-off-by: wujing +--- + src/client/connect/grpc/client_base.h | 4 +- + .../connect/grpc/grpc_containers_client.cc | 2 +- + src/client/connect/grpc/grpc_images_client.cc | 37 +++++++++++-------- + .../connect/grpc/grpc_volumes_client.cc | 27 +++++++------- + 4 files changed, 38 insertions(+), 32 deletions(-) + +diff --git a/src/client/connect/grpc/client_base.h b/src/client/connect/grpc/client_base.h +index f37bf471..dbe130cd 100644 +--- a/src/client/connect/grpc/client_base.h ++++ b/src/client/connect/grpc/client_base.h +@@ -41,7 +41,7 @@ class ClientBase { + public: + explicit ClientBase(void *args) + { +- client_connect_config_t *arguments = reinterpret_cast(args); ++ auto *arguments = reinterpret_cast(args); + + std::string socket_address = arguments->socket; + const std::string tcp_prefix = "tcp://"; +@@ -207,7 +207,7 @@ protected: + + std::unique_ptr stub_; + std::string m_tlsMode { ClientBaseConstants::TLS_OFF }; +- std::string m_certFile { "" }; ++ std::string m_certFile; + + unsigned int deadline; + }; +diff --git a/src/client/connect/grpc/grpc_containers_client.cc b/src/client/connect/grpc/grpc_containers_client.cc +index 822edd8f..ebe71df9 100644 +--- a/src/client/connect/grpc/grpc_containers_client.cc ++++ b/src/client/connect/grpc/grpc_containers_client.cc +@@ -2138,7 +2138,7 @@ public: + // Set common name from cert.perm + char common_name_value[ClientBaseConstants::COMMON_NAME_LEN] = { 0 }; + int ret = get_common_name_from_tls_cert(m_certFile.c_str(), common_name_value, +- ClientBaseConstants::COMMON_NAME_LEN); ++ ClientBaseConstants::COMMON_NAME_LEN); + if (ret != 0) { + ERROR("Failed to get common name in: %s", m_certFile.c_str()); + return -1; +diff --git a/src/client/connect/grpc/grpc_images_client.cc b/src/client/connect/grpc/grpc_images_client.cc +index 1bc12e69..50265e04 100644 +--- a/src/client/connect/grpc/grpc_images_client.cc ++++ b/src/client/connect/grpc/grpc_images_client.cc +@@ -81,8 +81,8 @@ public: + for (i = 0; i < num; i++) { + const Image &image = gresponse->images(i); + if (image.has_target()) { +- const char *media_type = +- !image.target().media_type().empty() ? image.target().media_type().c_str() : "-"; ++ const char *media_type = !image.target().media_type().empty() ? image.target().media_type().c_str() : ++ "-"; + images_list[i].type = util_strdup_s(media_type); + const char *digest = !image.target().digest().empty() ? image.target().digest().c_str() : "-"; + images_list[i].digest = util_strdup_s(digest); +@@ -336,9 +336,9 @@ public: + } + }; + +-class ImagesPull : public +- ClientBase { ++class ImagesPull : public ClientBase { + public: + explicit ImagesPull(void *args) + : ClientBase(args) +@@ -346,14 +346,15 @@ public: + } + ~ImagesPull() = default; + +- auto request_to_grpc(const isula_pull_request *request, runtime::v1alpha2::PullImageRequest *grequest) -> int override ++ auto request_to_grpc(const isula_pull_request *request, runtime::v1alpha2::PullImageRequest *grequest) ++ -> int override + { + if (request == nullptr) { + return -1; + } + + if (request->image_name != nullptr) { +- runtime::v1alpha2::ImageSpec *image_spec = new (std::nothrow) runtime::v1alpha2::ImageSpec; ++ auto *image_spec = new (std::nothrow) runtime::v1alpha2::ImageSpec; + if (image_spec == nullptr) { + return -1; + } +@@ -364,7 +365,8 @@ public: + return 0; + } + +- auto response_from_grpc(runtime::v1alpha2::PullImageResponse *gresponse, isula_pull_response *response) -> int override ++ auto response_from_grpc(runtime::v1alpha2::PullImageResponse *gresponse, isula_pull_response *response) ++ -> int override + { + if (!gresponse->image_ref().empty()) { + response->image_ref = util_strdup_s(gresponse->image_ref().c_str()); +@@ -437,17 +439,20 @@ public: + return 0; + } + +- auto grpc_call(ClientContext *context, const InspectImageRequest &req, InspectImageResponse *reply) -> Status override ++ auto grpc_call(ClientContext *context, const InspectImageRequest &req, InspectImageResponse *reply) ++ -> Status override + { + return stub_->Inspect(context, req, reply); + } + }; + +-class Login : public +- ClientBase { + public: +- explicit Login(void *args) : ClientBase(args) {} ++ explicit Login(void *args) ++ : ClientBase(args) ++ { ++ } + ~Login() = default; + + auto request_to_grpc(const isula_login_request *request, LoginRequest *grequest) -> int override +@@ -511,11 +516,13 @@ public: + } + }; + +-class Logout : public +- ClientBase { + public: +- explicit Logout(void *args) : ClientBase(args) {} ++ explicit Logout(void *args) ++ : ClientBase(args) ++ { ++ } + ~Logout() = default; + + auto request_to_grpc(const isula_logout_request *request, LogoutRequest *grequest) -> int override +diff --git a/src/client/connect/grpc/grpc_volumes_client.cc b/src/client/connect/grpc/grpc_volumes_client.cc +index d8eb74b2..5d55b8c8 100644 +--- a/src/client/connect/grpc/grpc_volumes_client.cc ++++ b/src/client/connect/grpc/grpc_volumes_client.cc +@@ -27,10 +27,10 @@ using grpc::ClientContext; + using grpc::Status; + + class VolumeList : public ClientBase { ++ isula_list_volume_response, ListVolumeResponse> { + public: + explicit VolumeList(void *args) +- : ClientBase(args) ++ : ClientBase(args) + { + } + ~VolumeList() = default; +@@ -57,8 +57,8 @@ public: + response->cc = ISULAD_ERR_MEMOUT; + return -1; + } +- auto volumes = static_cast( +- util_common_calloc_s(sizeof(struct isula_volume_info) * static_cast(num))); ++ auto *volumes = static_cast( ++ util_smart_calloc_s(sizeof(struct isula_volume_info), static_cast(num))); + if (volumes == nullptr) { + ERROR("out of memory"); + response->cc = ISULAD_ERR_MEMOUT; +@@ -89,12 +89,11 @@ public: + } + }; + +-class VolumeRemove : public +- ClientBase { ++class VolumeRemove : public ClientBase { + public: + explicit VolumeRemove(void *args) +- : ClientBase(args) ++ : ClientBase(args) + { + } + ~VolumeRemove() = default; +@@ -135,18 +134,18 @@ public: + return 0; + } + +- auto grpc_call(ClientContext *context, const RemoveVolumeRequest &req, RemoveVolumeResponse *reply) -> Status override ++ auto grpc_call(ClientContext *context, const RemoveVolumeRequest &req, RemoveVolumeResponse *reply) ++ -> Status override + { + return stub_->Remove(context, req, reply); + } + }; + +-class VolumePrune : public +- ClientBase { ++class VolumePrune : public ClientBase { + public: + explicit VolumePrune(void *args) +- : ClientBase(args) ++ : ClientBase(args) + { + } + ~VolumePrune() = default; +@@ -158,7 +157,7 @@ public: + auto size = gresponse->volumes_size(); + if (size != 0) { + response->volumes = static_cast(util_common_calloc_s(sizeof(char *) * size)); +- if (response->volumes == NULL) { ++ if (response->volumes == nullptr) { + return -1; + } + +-- +2.20.1 + diff --git a/0011-remove-redundant-code.patch b/0011-remove-redundant-code.patch new file mode 100644 index 0000000..61b788b --- /dev/null +++ b/0011-remove-redundant-code.patch @@ -0,0 +1,238 @@ +From 3e2793ee0124dff55464ad78d34ab2288ab7c382 Mon Sep 17 00:00:00 2001 +From: wujing +Date: Mon, 28 Feb 2022 19:40:45 +0800 +Subject: [PATCH 11/16] remove redundant code + +Signed-off-by: wujing +--- + .../connect/grpc/grpc_volumes_client.cc | 16 +++++++------- + src/client/connect/protocol_type.c | 22 +------------------ + 2 files changed, 9 insertions(+), 29 deletions(-) + +diff --git a/src/client/connect/grpc/grpc_volumes_client.cc b/src/client/connect/grpc/grpc_volumes_client.cc +index 5d55b8c8..902e8a13 100644 +--- a/src/client/connect/grpc/grpc_volumes_client.cc ++++ b/src/client/connect/grpc/grpc_volumes_client.cc +@@ -27,10 +27,10 @@ using grpc::ClientContext; + using grpc::Status; + + class VolumeList : public ClientBase { ++ isula_list_volume_response, ListVolumeResponse> { + public: + explicit VolumeList(void *args) +- : ClientBase(args) ++ : ClientBase(args) + { + } + ~VolumeList() = default; +@@ -58,7 +58,7 @@ public: + return -1; + } + auto *volumes = static_cast( +- util_smart_calloc_s(sizeof(struct isula_volume_info), static_cast(num))); ++ util_smart_calloc_s(sizeof(struct isula_volume_info), static_cast(num))); + if (volumes == nullptr) { + ERROR("out of memory"); + response->cc = ISULAD_ERR_MEMOUT; +@@ -90,10 +90,10 @@ public: + }; + + class VolumeRemove : public ClientBase { ++ RemoveVolumeRequest, isula_remove_volume_response, RemoveVolumeResponse> { + public: + explicit VolumeRemove(void *args) +- : ClientBase(args) ++ : ClientBase(args) + { + } + ~VolumeRemove() = default; +@@ -135,17 +135,17 @@ public: + } + + auto grpc_call(ClientContext *context, const RemoveVolumeRequest &req, RemoveVolumeResponse *reply) +- -> Status override ++ -> Status override + { + return stub_->Remove(context, req, reply); + } + }; + + class VolumePrune : public ClientBase { ++ PruneVolumeRequest, isula_prune_volume_response, PruneVolumeResponse> { + public: + explicit VolumePrune(void *args) +- : ClientBase(args) ++ : ClientBase(args) + { + } + ~VolumePrune() = default; +diff --git a/src/client/connect/protocol_type.c b/src/client/connect/protocol_type.c +index 3e5dafb1..af582abf 100644 +--- a/src/client/connect/protocol_type.c ++++ b/src/client/connect/protocol_type.c +@@ -916,7 +916,6 @@ void isula_create_image_request_free(struct isula_create_image_request *request) + request->image_info.digest = NULL; + + free(request); +- return; + } + + /* isula create image response free */ +@@ -939,7 +938,6 @@ void isula_create_image_response_free(struct isula_create_image_response *respon + response->image_info.digest = NULL; + + free(response); +- return; + } + + /* isula images list free */ +@@ -959,7 +957,6 @@ void isula_images_list_free(size_t images_num, struct isula_image_info *images_l + } + + free(images_list); +- return; + } + + /* isula list images request free */ +@@ -970,7 +967,6 @@ void isula_list_images_request_free(struct isula_list_images_request *request) + } + + free(request); +- return; + } + + /* isula list images response free */ +@@ -1000,7 +996,6 @@ void isula_rmi_request_free(struct isula_rmi_request *request) + request->image_name = NULL; + + free(request); +- return; + } + + /* isula rmi response free */ +@@ -1014,7 +1009,6 @@ void isula_rmi_response_free(struct isula_rmi_response *response) + response->errmsg = NULL; + + free(response); +- return; + } + + /* isula tag request free */ +@@ -1030,7 +1024,6 @@ void isula_tag_request_free(struct isula_tag_request *request) + request->dest_name = NULL; + + free(request); +- return; + } + + /* isula tag response free */ +@@ -1044,7 +1037,6 @@ void isula_tag_response_free(struct isula_tag_response *response) + response->errmsg = NULL; + + free(response); +- return; + } + + /* isula pull response free */ +@@ -1058,7 +1050,6 @@ void isula_pull_request_free(struct isula_pull_request *request) + request->image_name = NULL; + + free(request); +- return; + } + + /* isula pull response free */ +@@ -1074,7 +1065,6 @@ void isula_pull_response_free(struct isula_pull_response *response) + free(response->errmsg); + response->errmsg = NULL; + free(response); +- return; + } + + /* isula import request free */ +@@ -1091,7 +1081,6 @@ void isula_import_request_free(struct isula_import_request *request) + request->tag = NULL; + + free(request); +- return; + } + + /* isula import response free */ +@@ -1108,7 +1097,6 @@ void isula_import_response_free(struct isula_import_response *response) + response->errmsg = NULL; + + free(response); +- return; + } + + /* isula load request free */ +@@ -1128,7 +1116,6 @@ void isula_load_request_free(struct isula_load_request *request) + request->tag = NULL; + + free(request); +- return; + } + + /* isula load response free */ +@@ -1142,7 +1129,6 @@ void isula_load_response_free(struct isula_load_response *response) + response->errmsg = NULL; + + free(response); +- return; + } + + /* isula login response free */ +@@ -1156,7 +1142,6 @@ void isula_login_response_free(struct isula_login_response *response) + response->errmsg = NULL; + + free(response); +- return; + } + + /* isula logout response free */ +@@ -1170,7 +1155,6 @@ void isula_logout_response_free(struct isula_logout_response *response) + response->errmsg = NULL; + + free(response); +- return; + } + + /* isula export request free */ +@@ -1331,8 +1315,6 @@ void isula_volume_list_free(size_t volumes_len, struct isula_volume_info *volume + free(volume->name); + } + free(volumes); +- +- return; + } + + void isula_list_volume_response_free(struct isula_list_volume_response *response) +@@ -1349,7 +1331,6 @@ void isula_list_volume_response_free(struct isula_list_volume_response *response + response->errmsg = NULL; + + free(response); +- return; + } + + void isula_remove_volume_response_free(struct isula_remove_volume_response *response) +@@ -1362,7 +1343,6 @@ void isula_remove_volume_response_free(struct isula_remove_volume_response *resp + response->errmsg = NULL; + + free(response); +- return; + } + + void isula_prune_volume_response_free(struct isula_prune_volume_response *response) +@@ -1386,5 +1366,5 @@ void isula_prune_volume_response_free(struct isula_prune_volume_response *respon + response->errmsg = NULL; + + free(response); +- return; + } ++ +-- +2.20.1 + diff --git a/0012-fix-coding-irregularities-of-entry-module.patch b/0012-fix-coding-irregularities-of-entry-module.patch new file mode 100644 index 0000000..515122d --- /dev/null +++ b/0012-fix-coding-irregularities-of-entry-module.patch @@ -0,0 +1,501 @@ +From 067caad399deb58eac9aefee85011ab9aff32f54 Mon Sep 17 00:00:00 2001 +From: wujing +Date: Mon, 28 Feb 2022 20:30:08 +0800 +Subject: [PATCH 12/16] fix coding irregularities of entry module + +Signed-off-by: wujing +--- + .../connect/grpc/grpc_containers_service.cc | 31 +++++++++---------- + .../connect/grpc/grpc_containers_service.h | 3 +- + .../entry/connect/grpc/grpc_images_service.cc | 24 ++++++-------- + .../entry/connect/grpc/grpc_images_service.h | 3 +- + .../connect/grpc/grpc_server_tls_auth.cc | 5 ++- + .../entry/connect/grpc/grpc_server_tls_auth.h | 5 ++- + .../connect/grpc/grpc_volumes_service.cc | 12 +++---- + src/daemon/entry/cri/cri_constants.cc | 4 +-- + src/daemon/entry/cri/errors.cc | 2 +- + src/daemon/entry/cri/errors.h | 2 +- + src/daemon/entry/cri/network_plugin.cc | 9 +++--- + src/daemon/entry/cri/request_cache.cc | 2 +- + .../entry/cri/websocket/service/exec_serve.cc | 2 +- + .../entry/cri/websocket/service/ws_server.h | 1 + + 14 files changed, 48 insertions(+), 57 deletions(-) + +diff --git a/src/daemon/entry/connect/grpc/grpc_containers_service.cc b/src/daemon/entry/connect/grpc/grpc_containers_service.cc +index 54529998..f3066af4 100644 +--- a/src/daemon/entry/connect/grpc/grpc_containers_service.cc ++++ b/src/daemon/entry/connect/grpc/grpc_containers_service.cc +@@ -99,8 +99,8 @@ bool grpc_add_initial_metadata(void *context, const char *header, const char *va + + bool grpc_event_write_function(void *writer, void *data) + { +- struct isulad_events_format *event = (struct isulad_events_format *)data; +- ServerWriter *gwriter = (ServerWriter *)writer; ++ auto *event = (struct isulad_events_format *)data; ++ auto *gwriter = (ServerWriter *)writer; + Event gevent; + if (event_to_grpc(event, &gevent) != 0) { + return false; +@@ -110,8 +110,8 @@ bool grpc_event_write_function(void *writer, void *data) + + bool grpc_copy_from_container_write_function(void *writer, void *data) + { +- struct isulad_copy_from_container_response *copy = (struct isulad_copy_from_container_response *)data; +- ServerWriter *gwriter = (ServerWriter *)writer; ++ auto *copy = (struct isulad_copy_from_container_response *)data; ++ auto *gwriter = (ServerWriter *)writer; + CopyFromContainerResponse gcopy; + copy_from_container_response_to_grpc(copy, &gcopy); + return gwriter->Write(gcopy); +@@ -137,9 +137,8 @@ static bool copy_to_container_data_from_grpc(struct isulad_copy_to_container_dat + + bool grpc_copy_to_container_read_function(void *reader, void *data) + { +- struct isulad_copy_to_container_data *copy = (struct isulad_copy_to_container_data *)data; +- ServerReaderWriter *stream = +- (ServerReaderWriter *)reader; ++ auto *copy = (struct isulad_copy_to_container_data *)data; ++ auto *stream = (ServerReaderWriter *)reader; + CopyToContainerRequest gcopy; + if (!stream->Read(&gcopy)) { + return false; +@@ -287,7 +286,7 @@ ssize_t WriteStartResponseToRemoteClient(void *context, const void *data, size_t + return 0; + } + +- struct RemoteStartContext *ctx = (struct RemoteStartContext *)context; ++ auto *ctx = (struct RemoteStartContext *)context; + RemoteStartResponse response; + if (ctx->isStdout) { + response.set_stdout((char *)data, len); +@@ -306,7 +305,7 @@ int grpc_start_stream_close(void *context, char **err) + { + int ret = 0; + (void)err; +- struct RemoteStartContext *ctx = (struct RemoteStartContext *)context; ++ auto *ctx = (struct RemoteStartContext *)context; + RemoteStartResponse finish_response; + finish_response.set_finish(true); + if (!ctx->stream->Write(finish_response)) { +@@ -374,7 +373,7 @@ Status ContainerServiceImpl::RemoteStart(ServerContext *context, + if (request.finish()) { + break; + } +- std::string command = request.stdin(); ++ const std::string &command = request.stdin(); + if (write(read_pipe_fd[1], (void *)(command.c_str()), command.length()) < 0) { + ERROR("sub write over!"); + break; +@@ -593,7 +592,7 @@ ssize_t WriteExecStdoutResponseToRemoteClient(void *context, const void *data, s + if (context == nullptr || data == nullptr || len == 0) { + return 0; + } +- auto stream = static_cast *>(context); ++ auto *stream = static_cast *>(context); + RemoteExecResponse response; + response.set_stdout((char *)data, len); + if (!stream->Write(response)) { +@@ -608,7 +607,7 @@ ssize_t WriteExecStderrResponseToRemoteClient(void *context, const void *data, s + if (context == nullptr || data == nullptr || len == 0) { + return 0; + } +- auto stream = static_cast *>(context); ++ auto *stream = static_cast *>(context); + RemoteExecResponse response; + response.set_stderr((char *)data, len); + if (!stream->Write(response)) { +@@ -809,7 +808,7 @@ ssize_t WriteAttachResponseToRemoteClient(void *context, const void *data, size_ + if (context == nullptr || data == nullptr || len == 0) { + return 0; + } +- struct AttachContext *ctx = (struct AttachContext *)context; ++ auto *ctx = (struct AttachContext *)context; + AttachResponse response; + if (ctx->isStdout) { + response.set_stdout((char *)data, len); +@@ -828,7 +827,7 @@ int grpc_attach_stream_close(void *context, char **err) + { + int ret = 0; + (void)err; +- struct AttachContext *ctx = (struct AttachContext *)context; ++ auto *ctx = (struct AttachContext *)context; + AttachResponse finish_response; + finish_response.set_finish(true); + if (!ctx->stream->Write(finish_response)) { +@@ -1372,8 +1371,8 @@ int ContainerServiceImpl::logs_request_from_grpc(const LogsRequest *grequest, st + + bool grpc_logs_write_function(void *writer, void *data) + { +- logger_json_file *log = static_cast(data); +- ServerWriter *gwriter = static_cast *>(writer); ++ auto *log = static_cast(data); ++ auto *gwriter = static_cast *>(writer); + LogsResponse gresponse; + log_to_grpc(log, &gresponse); + return gwriter->Write(gresponse); +diff --git a/src/daemon/entry/connect/grpc/grpc_containers_service.h b/src/daemon/entry/connect/grpc/grpc_containers_service.h +index 4865c41e..d87e7e9f 100644 +--- a/src/daemon/entry/connect/grpc/grpc_containers_service.h ++++ b/src/daemon/entry/connect/grpc/grpc_containers_service.h +@@ -112,11 +112,12 @@ private: + gresponse->set_cc(ISULAD_ERR_MEMOUT); + return; + } ++ + gresponse->set_cc(response->cc); ++ + if (response->errmsg != nullptr) { + gresponse->set_errmsg(response->errmsg); + } +- return; + } + + int version_request_from_grpc(const VersionRequest *grequest, container_version_request **request); +diff --git a/src/daemon/entry/connect/grpc/grpc_images_service.cc b/src/daemon/entry/connect/grpc/grpc_images_service.cc +index 57a51ee0..dff07b39 100644 +--- a/src/daemon/entry/connect/grpc/grpc_images_service.cc ++++ b/src/daemon/entry/connect/grpc/grpc_images_service.cc +@@ -29,8 +29,7 @@ int ImagesServiceImpl::image_list_request_from_grpc(const ListImagesRequest *gre + image_list_images_request **request) + { + size_t len = 0; +- image_list_images_request *tmpreq = +- (image_list_images_request *)util_common_calloc_s(sizeof(image_list_images_request)); ++ auto *tmpreq = (image_list_images_request *)util_common_calloc_s(sizeof(image_list_images_request)); + if (tmpreq == nullptr) { + ERROR("Out of memory"); + return -1; +@@ -63,7 +62,7 @@ int ImagesServiceImpl::image_list_request_from_grpc(const ListImagesRequest *gre + goto cleanup; + } + +- for (auto &iter : grequest->filters()) { ++ for (const auto &iter : grequest->filters()) { + tmpreq->filters->values[tmpreq->filters->len] = + (json_map_string_bool *)util_common_calloc_s(sizeof(json_map_string_bool)); + if (tmpreq->filters->values[tmpreq->filters->len] == nullptr) { +@@ -71,7 +70,7 @@ int ImagesServiceImpl::image_list_request_from_grpc(const ListImagesRequest *gre + goto cleanup; + } + if (append_json_map_string_bool(tmpreq->filters->values[tmpreq->filters->len], +- iter.second.empty() ? "" : iter.second.c_str(), true)) { ++ iter.second.empty() ? "" : iter.second.c_str(), true) != 0) { + free(tmpreq->filters->values[tmpreq->filters->len]); + tmpreq->filters->values[tmpreq->filters->len] = nullptr; + ERROR("Append failed"); +@@ -129,15 +128,12 @@ void ImagesServiceImpl::image_list_response_to_grpc(image_list_images_response * + target->set_size(response->images[i]->target->size); + image->set_allocated_target(target); + } +- +- return; + } + + int ImagesServiceImpl::image_remove_request_from_grpc(const DeleteImageRequest *grequest, + image_delete_image_request **request) + { +- image_delete_image_request *tmpreq = +- (image_delete_image_request *)util_common_calloc_s(sizeof(image_delete_image_request)); ++ auto *tmpreq = (image_delete_image_request *)util_common_calloc_s(sizeof(image_delete_image_request)); + if (tmpreq == nullptr) { + ERROR("Out of memory"); + return -1; +@@ -154,7 +150,7 @@ int ImagesServiceImpl::image_remove_request_from_grpc(const DeleteImageRequest * + + int ImagesServiceImpl::image_tag_request_from_grpc(const TagImageRequest *grequest, image_tag_image_request **request) + { +- image_tag_image_request *tmpreq = (image_tag_image_request *)util_common_calloc_s(sizeof(image_tag_image_request)); ++ auto *tmpreq = (image_tag_image_request *)util_common_calloc_s(sizeof(image_tag_image_request)); + if (tmpreq == nullptr) { + ERROR("Out of memory"); + return -1; +@@ -193,8 +189,7 @@ int ImagesServiceImpl::image_import_request_from_grpc(const ImportRequest *grequ + int ImagesServiceImpl::image_load_request_from_grpc(const LoadImageRequest *grequest, + image_load_image_request **request) + { +- image_load_image_request *tmpreq = +- (image_load_image_request *)util_common_calloc_s(sizeof(image_load_image_request)); ++ auto *tmpreq = (image_load_image_request *)util_common_calloc_s(sizeof(image_load_image_request)); + if (tmpreq == nullptr) { + ERROR("Out of memory"); + return -1; +@@ -216,7 +211,7 @@ int ImagesServiceImpl::image_load_request_from_grpc(const LoadImageRequest *greq + + int ImagesServiceImpl::inspect_request_from_grpc(const InspectImageRequest *grequest, image_inspect_request **request) + { +- image_inspect_request *tmpreq = (image_inspect_request *)util_common_calloc_s(sizeof(image_inspect_request)); ++ auto *tmpreq = (image_inspect_request *)util_common_calloc_s(sizeof(image_inspect_request)); + if (tmpreq == nullptr) { + ERROR("Out of memory"); + return -1; +@@ -352,7 +347,6 @@ void ImagesServiceImpl::import_response_to_grpc(const image_import_response *res + if (response->errmsg != nullptr) { + gresponse->set_errmsg(response->errmsg); + } +- return; + } + + Status ImagesServiceImpl::Import(ServerContext *context, const ImportRequest *request, ImportResponse *reply) +@@ -449,7 +443,7 @@ Status ImagesServiceImpl::Inspect(ServerContext *context, const InspectImageRequ + + int ImagesServiceImpl::image_login_request_from_grpc(const LoginRequest *grequest, image_login_request **request) + { +- image_login_request *tmpreq = (image_login_request *)util_common_calloc_s(sizeof(image_login_request)); ++ auto *tmpreq = (image_login_request *)util_common_calloc_s(sizeof(image_login_request)); + if (tmpreq == nullptr) { + ERROR("Out of memory"); + return -1; +@@ -474,7 +468,7 @@ int ImagesServiceImpl::image_login_request_from_grpc(const LoginRequest *greques + + int ImagesServiceImpl::image_logout_request_from_grpc(const LogoutRequest *grequest, image_logout_request **request) + { +- image_logout_request *tmpreq = (image_logout_request *)util_common_calloc_s(sizeof(image_logout_request)); ++ auto *tmpreq = (image_logout_request *)util_common_calloc_s(sizeof(image_logout_request)); + if (tmpreq == nullptr) { + ERROR("Out of memory"); + return -1; +diff --git a/src/daemon/entry/connect/grpc/grpc_images_service.h b/src/daemon/entry/connect/grpc/grpc_images_service.h +index 92334b52..8ad486fd 100644 +--- a/src/daemon/entry/connect/grpc/grpc_images_service.h ++++ b/src/daemon/entry/connect/grpc/grpc_images_service.h +@@ -66,11 +66,12 @@ private: + gresponse->set_cc(ISULAD_ERR_MEMOUT); + return; + } ++ + gresponse->set_cc(response->cc); ++ + if (response->errmsg != nullptr) { + gresponse->set_errmsg(response->errmsg); + } +- return; + } + int image_list_request_from_grpc(const ListImagesRequest *grequest, image_list_images_request **request); + +diff --git a/src/daemon/entry/connect/grpc/grpc_server_tls_auth.cc b/src/daemon/entry/connect/grpc/grpc_server_tls_auth.cc +index 1bb1b928..6e958e23 100644 +--- a/src/daemon/entry/connect/grpc/grpc_server_tls_auth.cc ++++ b/src/daemon/entry/connect/grpc/grpc_server_tls_auth.cc +@@ -20,12 +20,12 @@ + + namespace AuthorizationPluginConfig { + std::string auth_plugin = ""; +-}; ++} // namespace AuthorizationPluginConfig + + namespace GrpcServerTlsAuth { + Status auth(ServerContext *context, std::string action) + { +- const std::multimap init_metadata = context->client_metadata(); ++ const std::multimap &init_metadata = context->client_metadata(); + auto tls_mode_kv = init_metadata.find("tls_mode"); + if (tls_mode_kv == init_metadata.end()) { + return Status(StatusCode::UNKNOWN, "unknown error"); +@@ -58,4 +58,3 @@ Status auth(ServerContext *context, std::string action) + return Status::OK; + } + } // namespace GrpcServerTlsAuth +- +diff --git a/src/daemon/entry/connect/grpc/grpc_server_tls_auth.h b/src/daemon/entry/connect/grpc/grpc_server_tls_auth.h +index f490ef86..ee66529f 100644 +--- a/src/daemon/entry/connect/grpc/grpc_server_tls_auth.h ++++ b/src/daemon/entry/connect/grpc/grpc_server_tls_auth.h +@@ -24,11 +24,10 @@ using grpc::StatusCode; + + namespace AuthorizationPluginConfig { + extern std::string auth_plugin; +-}; ++}; // namespace AuthorizationPluginConfig + + namespace GrpcServerTlsAuth { + Status auth(ServerContext *context, std::string action); +-}; ++}; // namespace GrpcServerTlsAuth + + #endif // DAEMON_ENTRY_CONNECT_GRPC_GRPC_SERVER_TLS_AUTH_H +- +diff --git a/src/daemon/entry/connect/grpc/grpc_volumes_service.cc b/src/daemon/entry/connect/grpc/grpc_volumes_service.cc +index fcc7210e..8b090486 100644 +--- a/src/daemon/entry/connect/grpc/grpc_volumes_service.cc ++++ b/src/daemon/entry/connect/grpc/grpc_volumes_service.cc +@@ -28,8 +28,7 @@ + int VolumeServiceImpl::volume_list_request_from_grpc(const ListVolumeRequest *grequest, + volume_list_volume_request **request) + { +- volume_list_volume_request *tmpreq = +- static_cast(util_common_calloc_s(sizeof(volume_list_volume_request))); ++ auto *tmpreq = static_cast(util_common_calloc_s(sizeof(volume_list_volume_request))); + if (tmpreq == nullptr) { + ERROR("Out of memory"); + return -1; +@@ -53,7 +52,7 @@ int VolumeServiceImpl::volume_list_response_to_grpc(volume_list_volume_response + } + + for (size_t i {}; i < response->volumes_len; i++) { +- auto volume = gresponse->add_volumes(); ++ auto *volume = gresponse->add_volumes(); + if (response->volumes[i]->driver != nullptr) { + volume->set_driver(response->volumes[i]->driver); + } +@@ -68,7 +67,7 @@ int VolumeServiceImpl::volume_list_response_to_grpc(volume_list_volume_response + int VolumeServiceImpl::volume_remove_request_from_grpc(const RemoveVolumeRequest *grequest, + volume_remove_volume_request **request) + { +- volume_remove_volume_request *tmpreq = ++ auto *tmpreq = + static_cast(util_common_calloc_s(sizeof(volume_remove_volume_request))); + if (tmpreq == nullptr) { + ERROR("Out of memory"); +@@ -86,7 +85,7 @@ int VolumeServiceImpl::volume_remove_request_from_grpc(const RemoveVolumeRequest + int VolumeServiceImpl::volume_prune_request_from_grpc(const PruneVolumeRequest *grequest, + volume_prune_volume_request **request) + { +- volume_prune_volume_request *tmpreq = ++ auto *tmpreq = + static_cast(util_common_calloc_s(sizeof(volume_prune_volume_request))); + if (tmpreq == nullptr) { + ERROR("Out of memory"); +@@ -117,14 +116,13 @@ int VolumeServiceImpl::volume_prune_response_to_grpc(volume_prune_volume_respons + return 0; + } + +- + Status VolumeServiceImpl::List(ServerContext *context, const ListVolumeRequest *request, ListVolumeResponse *reply) + { + auto status = GrpcServerTlsAuth::auth(context, "volume_list"); + if (!status.ok()) { + return status; + } +- auto cb = get_service_executor(); ++ auto *cb = get_service_executor(); + if (cb == nullptr || cb->volume.list == nullptr) { + return Status(StatusCode::UNIMPLEMENTED, "Unimplemented callback"); + } +diff --git a/src/daemon/entry/cri/cri_constants.cc b/src/daemon/entry/cri/cri_constants.cc +index 265e38e5..86cc2bb6 100644 +--- a/src/daemon/entry/cri/cri_constants.cc ++++ b/src/daemon/entry/cri/cri_constants.cc +@@ -12,7 +12,7 @@ + * Create: 2020-12-21 + * Description: provide cri constants definition + *********************************************************************************/ +-# include "cri_constants.h" ++#include "cri_constants.h" + + namespace CRI { + const std::string Constants::namespaceModeHost { "host" }; +@@ -22,4 +22,4 @@ const std::string Constants::kubePrefix { "k8s" }; + const std::string Constants::sandboxContainerName { "POD" }; + const std::string Constants::kubeAPIVersion { "0.1.0" }; + const std::string Constants::iSulaRuntimeName { "iSulad" }; +-} +\ No newline at end of file ++} // namespace CRI +diff --git a/src/daemon/entry/cri/errors.cc b/src/daemon/entry/cri/errors.cc +index 0dbee4a7..a80ca433 100644 +--- a/src/daemon/entry/cri/errors.cc ++++ b/src/daemon/entry/cri/errors.cc +@@ -90,7 +90,7 @@ void Errors::SetAggregate(const std::vector &msgs) + std::string result; + size_t size = msgs.size(); + +- if (!size) { ++ if (size == 0) { + return; + } + +diff --git a/src/daemon/entry/cri/errors.h b/src/daemon/entry/cri/errors.h +index 81e82ad2..193a9523 100644 +--- a/src/daemon/entry/cri/errors.h ++++ b/src/daemon/entry/cri/errors.h +@@ -44,7 +44,7 @@ public: + + private: + std::string m_message; +- int m_code; ++ int m_code{0}; + }; + + #endif // DAEMON_ENTRY_CRI_ERRORS_H +diff --git a/src/daemon/entry/cri/network_plugin.cc b/src/daemon/entry/cri/network_plugin.cc +index 2fa6ac26..00be975e 100644 +--- a/src/daemon/entry/cri/network_plugin.cc ++++ b/src/daemon/entry/cri/network_plugin.cc +@@ -27,7 +27,7 @@ + #include "cri_runtime_service.h" + + namespace Network { +-static void run_modprobe(void *args) ++static void run_modprobe(void * /*args*/) + { + execlp("modprobe", "modprobe", "br-netfilter", nullptr); + } +@@ -190,7 +190,7 @@ void InitNetworkPlugin(std::vector> *plugins, std + std::string hairpinMode, std::string nonMasqueradeCIDR, int mtu, + std::shared_ptr *result, Errors &err) + { +- std::string allErr { "" }; ++ std::string allErr; + + if (networkPluginName.empty()) { + DEBUG("network plugin name empty"); +@@ -233,7 +233,6 @@ void InitNetworkPlugin(std::vector> *plugins, std + } + + pluginMap.clear(); +- return; + } + + const std::string &NetworkPluginConf::GetDockershimRootDirectory() const +@@ -485,8 +484,8 @@ unlock: + Unlock(fullName, error); + } + +-void NoopNetworkPlugin::Init(const std::string &hairpinMode, +- const std::string &nonMasqueradeCIDR, int mtu, Errors &error) ++void NoopNetworkPlugin::Init(const std::string &hairpinMode, const std::string &nonMasqueradeCIDR, int mtu, ++ Errors &error) + { + char *stderr_str { nullptr }; + char *stdout_str { nullptr }; +diff --git a/src/daemon/entry/cri/request_cache.cc b/src/daemon/entry/cri/request_cache.cc +index 312a8071..36a2f3dc 100644 +--- a/src/daemon/entry/cri/request_cache.cc ++++ b/src/daemon/entry/cri/request_cache.cc +@@ -94,7 +94,7 @@ std::string RequestCache::UniqueToken() + for (int i {}; i < maxTries; ++i) { + char rawToken[rawTokenSize + 1]; + (void)memset(rawToken, 0, sizeof(rawToken)); +- if (util_generate_random_str(rawToken, (size_t)rawTokenSize)) { ++ if (util_generate_random_str(rawToken, (size_t)rawTokenSize) != 0) { + ERROR("Generate rawToken failed"); + continue; + } +diff --git a/src/daemon/entry/cri/websocket/service/exec_serve.cc b/src/daemon/entry/cri/websocket/service/exec_serve.cc +index bf41cb74..7b7d36b5 100644 +--- a/src/daemon/entry/cri/websocket/service/exec_serve.cc ++++ b/src/daemon/entry/cri/websocket/service/exec_serve.cc +@@ -88,7 +88,7 @@ int ExecServe::ExecuteStreamCommand(SessionData *lwsCtx, void *request) + int ret = cb->container.exec(m_request, &m_response, m_request->attach_stdin ? lwsCtx->pipes.at(0) : -1, + m_request->attach_stdout ? &StdoutstringWriter : nullptr, + m_request->attach_stderr ? &StderrstringWriter : nullptr); +- ++ + if (ret != 0) { + std::string message; + if (m_response != nullptr && m_response->errmsg != nullptr) { +diff --git a/src/daemon/entry/cri/websocket/service/ws_server.h b/src/daemon/entry/cri/websocket/service/ws_server.h +index 2d3bb4a7..4af54067 100644 +--- a/src/daemon/entry/cri/websocket/service/ws_server.h ++++ b/src/daemon/entry/cri/websocket/service/ws_server.h +@@ -23,6 +23,7 @@ + #include + #include + #include ++#include + #include + #include "route_callback_register.h" + #include "url.h" +-- +2.20.1 + diff --git a/0013-fix-coding-irregularities.patch b/0013-fix-coding-irregularities.patch new file mode 100644 index 0000000..3b3ad45 --- /dev/null +++ b/0013-fix-coding-irregularities.patch @@ -0,0 +1,187 @@ +From fb14a10d2e9bdf700dac71078327f9473ee06ed7 Mon Sep 17 00:00:00 2001 +From: wujing +Date: Mon, 28 Feb 2022 20:51:06 +0800 +Subject: [PATCH 13/16] fix coding irregularities + +Signed-off-by: wujing +--- + src/cmd/isulad/isulad_commands.c | 2 +- + src/daemon/common/selinux_label.c | 2 -- + src/daemon/common/sysinfo.c | 15 +++++++-------- + .../executor/container_cb/execution_create.c | 2 +- + .../executor/container_cb/execution_network.c | 2 +- + src/daemon/executor/container_cb/list.c | 11 +---------- + 6 files changed, 11 insertions(+), 23 deletions(-) + +diff --git a/src/cmd/isulad/isulad_commands.c b/src/cmd/isulad/isulad_commands.c +index b37c7208..2a0ccf92 100644 +--- a/src/cmd/isulad/isulad_commands.c ++++ b/src/cmd/isulad/isulad_commands.c +@@ -360,7 +360,7 @@ static int check_args_auth_plugin(const struct service_arguments *args) + int ret = 0; + + if (args->json_confs->authorization_plugin != NULL) { +- if (strcmp(args->json_confs->authorization_plugin, AUTH_PLUGIN)) { ++ if (strcmp(args->json_confs->authorization_plugin, AUTH_PLUGIN) != 0) { + COMMAND_ERROR("Invalid authorization plugin '%s'", args->json_confs->authorization_plugin); + ERROR("Invalid authorization plugin '%s'", args->json_confs->authorization_plugin); + ret = -1; +diff --git a/src/daemon/common/selinux_label.c b/src/daemon/common/selinux_label.c +index f6698e89..4472504d 100644 +--- a/src/daemon/common/selinux_label.c ++++ b/src/daemon/common/selinux_label.c +@@ -171,8 +171,6 @@ static void find_selinux_fs(char **fs) + } + // slow path: try to find among the mounts + find_selinux_fs_among_mounts(fs); +- +- return; + } + + static int get_state_selinuxfs(char **fs) +diff --git a/src/daemon/common/sysinfo.c b/src/daemon/common/sysinfo.c +index 652a3985..e60377dd 100644 +--- a/src/daemon/common/sysinfo.c ++++ b/src/daemon/common/sysinfo.c +@@ -1010,7 +1010,7 @@ free_out: + + static int get_cgroup_version() + { +- struct statfs fs = {0}; ++ struct statfs fs = { 0 }; + + if (statfs(CGROUP_MOUNTPOINT, &fs) != 0) { + ERROR("failed to statfs %s: %s", CGROUP_MOUNTPOINT, strerror(errno)); +@@ -1019,9 +1019,9 @@ static int get_cgroup_version() + + if (fs.f_type == CGROUP2_SUPER_MAGIC) { + return CGROUP_VERSION_2; +- } else { +- return CGROUP_VERSION_1; + } ++ ++ return CGROUP_VERSION_1; + } + + static bool is_hugetlb_max(const char *name) +@@ -1102,7 +1102,6 @@ static char **get_huge_page_sizes() + hps[index] = util_strdup_s(pos); + dup_free: + free(dup); +- continue; + } + free_out: + +@@ -1259,7 +1258,7 @@ static int cgroup2_enable_all() + char *controllers_str = NULL; + char *subtree_controller_str = NULL; + char **controllers = NULL; +- char enable_controllers[PATH_MAX] = {0}; ++ char enable_controllers[PATH_MAX] = { 0 }; + + controllers_str = util_read_content_from_file(CGROUP2_CONTROLLERS_PATH); + if (controllers_str == NULL || strlen(controllers_str) == 0 || +@@ -1329,7 +1328,7 @@ static int get_cgroup_info_v2(sysinfo_t *sysinfo, bool quiet) + int ret = 0; + int nret = 0; + char *size = NULL; +- char path[PATH_MAX] = {0}; ++ char path[PATH_MAX] = { 0 }; + + if (make_sure_cgroup2_isulad_path_exist() != 0) { + return -1; +@@ -1511,7 +1510,7 @@ mountinfo_t *get_mount_info(const char *pline) + + info->mountpoint = util_strdup_s(list[4]); + +- if (strcmp(list[6], "-")) { ++ if (strcmp(list[6], "-") != 0) { + info->optional = util_strdup_s(list[6]); + } + +@@ -1570,7 +1569,7 @@ mountinfo_t **getmountsinfo(void) + + while (getline(&pline, &length, fp) != -1) { + int index; +- mountinfo_t *info; ++ mountinfo_t *info = NULL; + + info = get_mount_info(pline); + if (info == NULL) { +diff --git a/src/daemon/executor/container_cb/execution_create.c b/src/daemon/executor/container_cb/execution_create.c +index 43734d19..850e0a0f 100644 +--- a/src/daemon/executor/container_cb/execution_create.c ++++ b/src/daemon/executor/container_cb/execution_create.c +@@ -1026,7 +1026,7 @@ static int get_request_image_info(const container_create_request *request, char + } + + // Do not use none image because none image has no config. +- if (strcmp(request->image, "none") && strcmp(request->image, "none:latest")) { ++ if (strcmp(request->image, "none") != 0 && strcmp(request->image, "none:latest") != 0) { + *image_name = util_strdup_s(request->image); + } + +diff --git a/src/daemon/executor/container_cb/execution_network.c b/src/daemon/executor/container_cb/execution_network.c +index d10e9d16..6ca79a8c 100644 +--- a/src/daemon/executor/container_cb/execution_network.c ++++ b/src/daemon/executor/container_cb/execution_network.c +@@ -1074,4 +1074,4 @@ int init_container_network_confs(const char *id, const char *rootpath, const hos + + out: + return ret; +-} +\ No newline at end of file ++} +diff --git a/src/daemon/executor/container_cb/list.c b/src/daemon/executor/container_cb/list.c +index 67fef06e..90f4a548 100644 +--- a/src/daemon/executor/container_cb/list.c ++++ b/src/daemon/executor/container_cb/list.c +@@ -173,8 +173,7 @@ static int insert_matched_id(char **ids, map_t *matches, void *value, size_t ids + for (i = 0; i < ids_len; i++) { + container_t *cont = containers_store_get_by_prefix(ids[i]); + if (cont != NULL) { +- bool inserted; +- inserted = map_insert(matches, cont->common_config->id, value); ++ bool inserted = map_insert(matches, cont->common_config->id, value); + container_unref(cont); + if (!inserted) { + ERROR("Insert map failed: %s", ids[i]); +@@ -328,8 +327,6 @@ static void dup_container_labels(const map_t *map_labels, const container_config + ERROR("Failed to dup container %s labels", common_config->id); + } + } +- +- return; + } + + static void dup_container_annotations(const container_config_v2_common_config *common_config, +@@ -345,8 +342,6 @@ static void dup_container_annotations(const container_config_v2_common_config *c + if (ret != 0) { + ERROR("Failed to dup container %s annotations", common_config->id); + } +- +- return; + } + + static void dup_container_created_time(const container_config_v2_common_config *common_config, +@@ -356,8 +351,6 @@ static void dup_container_created_time(const container_config_v2_common_config * + util_to_unix_nanos_from_str(common_config->created, &isuladinfo->created) != 0) { + ERROR("Failed to dup container %s created time", common_config->id); + } +- +- return; + } + + static void dup_container_image_ref(const container_config_v2_common_config *common_config, +@@ -368,8 +361,6 @@ static void dup_container_image_ref(const container_config_v2_common_config *com + } + + isuladinfo->image_ref = util_strdup_s(common_config->config->image_ref); +- +- return; + } + + static int convert_common_config_info(const map_t *map_labels, const container_config_v2_common_config *common_config, +-- +2.20.1 + diff --git a/0014-fix-ut-bug-and-arguments-check.patch b/0014-fix-ut-bug-and-arguments-check.patch new file mode 100644 index 0000000..4e3e61f --- /dev/null +++ b/0014-fix-ut-bug-and-arguments-check.patch @@ -0,0 +1,275 @@ +From 2ee5027ad7d9cd073ea2428a39c693f9c8963bfc Mon Sep 17 00:00:00 2001 +From: haozi007 +Date: Fri, 13 May 2022 10:31:02 +0100 +Subject: [PATCH 14/16] fix ut bug and arguments check + +1. hold_int must return error when invalid digits, ie. "root:x:1a"; +2. hold_string_list return NULL only overflow buffer, other return buff_start; +3. parse_line_gr must check hold_string_list return; +4. must check result argument is not NULL; +5. use '\xff' to check buffer is overflow; + +Signed-off-by: haozi007 +--- + .../modules/image/image_rootfs_handler.c | 2 +- + src/utils/cutils/utils_pwgr.c | 47 ++++++++++++++----- + test/cutils/utils_pwgr/group_sample | 1 + + test/cutils/utils_pwgr/passwd_sample | 1 + + test/cutils/utils_pwgr/utils_pwgr_ut.cc | 20 +++++--- + 5 files changed, 51 insertions(+), 20 deletions(-) + +diff --git a/src/daemon/modules/image/image_rootfs_handler.c b/src/daemon/modules/image/image_rootfs_handler.c +index 960d52c7..ac1afdc6 100644 +--- a/src/daemon/modules/image/image_rootfs_handler.c ++++ b/src/daemon/modules/image/image_rootfs_handler.c +@@ -84,7 +84,7 @@ static int proc_by_fpasswd(FILE *f_passwd, const char *user, defs_process_user * + int uret = -1; + bool userfound = false; + long long n_user = 0; +- char buf[BUFSIZ]; ++ char buf[BUFSIZ] = { 0 }; + struct passwd pw; + struct passwd *pwbufp = NULL; + +diff --git a/src/utils/cutils/utils_pwgr.c b/src/utils/cutils/utils_pwgr.c +index f4588268..17cf017b 100644 +--- a/src/utils/cutils/utils_pwgr.c ++++ b/src/utils/cutils/utils_pwgr.c +@@ -57,6 +57,10 @@ static int hold_int(const char delim, bool required, char **src, unsigned int *d + } + + res = strtoll(*src, &err_str, 0); ++ if (err_str == *src) { ++ ERROR("invalid digits string."); ++ return -1; ++ } + if (errno == ERANGE) { + ERROR("Parse int from string failed."); + return -1; +@@ -158,9 +162,6 @@ static char **hold_string_list(char **line, char *buf_start, char *buf_end, cons + char **result = NULL; + char **walker = NULL; + +- if (**line == '\0') { +- return 0; +- } + // For ultimate space usage, the blank area from buffer which was allocated from stack is used + buf_start += __alignof__(char *) - 1; + // align the starting position of the buffer to use it as a 2d array +@@ -174,7 +175,7 @@ static char **hold_string_list(char **line, char *buf_start, char *buf_end, cons + (void)util_trim_space(*line); + if (hold_string(',', line, walker) != 0) { + ERROR("Parse string list error."); +- return NULL; ++ return result; + } + + if ((char *)(walker + 2) > buf_end) { +@@ -218,6 +219,10 @@ static int parse_line_gr(const char delim, char *line, size_t buflen, struct gro + } + + result->gr_mem = hold_string_list(&line, freebuff, buffend, ','); ++ if (result->gr_mem == NULL) { ++ ERROR("overflow of buffer."); ++ return -1; ++ } + + return 0; + } +@@ -225,8 +230,10 @@ static int parse_line_gr(const char delim, char *line, size_t buflen, struct gro + int util_getpwent_r(FILE *stream, struct passwd *resbuf, char *buffer, size_t buflen, struct passwd **result) + { + const char delim = ':'; ++ char *buff_end = NULL; ++ bool got = false; + +- if (stream == NULL || resbuf == NULL || buffer == NULL) { ++ if (stream == NULL || resbuf == NULL || buffer == NULL || result == NULL) { + ERROR("Password obj, params is NULL."); + return -1; + } +@@ -242,28 +249,34 @@ int util_getpwent_r(FILE *stream, struct passwd *resbuf, char *buffer, size_t bu + } + + __fsetlocking(stream, FSETLOCKING_BYCALLER); +- buffer[buflen - 1] = '\0'; + + if (feof(stream)) { + *result = NULL; + return ENOENT; + } ++ buff_end = buffer + buflen - 1; + +- while (fgets(buffer, buflen, stream) != NULL) { ++ while ((*buff_end = '\xff') && fgets(buffer, buflen, stream) != NULL) { + (void)util_trim_space(buffer); + if (buffer[0] == '\0' || buffer[0] == '#' || strlen(buffer) < 1) { + continue; + } + + if (parse_line_pw(delim, buffer, resbuf) == 0) { ++ got = true; + break; + } + +- if (buffer[buflen - 1] != '\0') { ++ if (*buff_end != '\xff') { + *result = NULL; + return ERANGE; + } + } ++ if (!got) { ++ *result = NULL; ++ return ERANGE; ++ } ++ + *result = resbuf; + + return 0; +@@ -272,8 +285,10 @@ int util_getpwent_r(FILE *stream, struct passwd *resbuf, char *buffer, size_t bu + int util_getgrent_r(FILE *stream, struct group *resbuf, char *buffer, size_t buflen, struct group **result) + { + const char delim = ':'; ++ char *buff_end = NULL; ++ bool got = false; + +- if (stream == NULL || resbuf == NULL || buffer == NULL) { ++ if (stream == NULL || resbuf == NULL || buffer == NULL || result == NULL) { + ERROR("Group obj, params is NULL."); + return -1; + } +@@ -289,29 +304,35 @@ int util_getgrent_r(FILE *stream, struct group *resbuf, char *buffer, size_t buf + } + + __fsetlocking(stream, FSETLOCKING_BYCALLER); +- buffer[buflen - 1] = '\0'; + + if (feof(stream)) { + *result = NULL; + return ENOENT; + } ++ buff_end = buffer + buflen - 1; + +- while (fgets(buffer, buflen, stream) != NULL) { ++ while ((*buff_end = '\xff') && fgets(buffer, buflen, stream) != NULL) { + (void)util_trim_space(buffer); + if (buffer[0] == '\0' || buffer[0] == '#' || strlen(buffer) < 1) { + continue; + } + + if (parse_line_gr(delim, buffer, buflen, resbuf) == 0) { ++ got = true; + break; + } + +- if (buffer[buflen - 1] != '\0') { ++ if (*buff_end != '\xff') { + *result = NULL; + return ERANGE; + } + } +- *result = resbuf; + ++ if (!got) { ++ *result = NULL; ++ return ERANGE; ++ } ++ ++ *result = resbuf; + return 0; + } +\ No newline at end of file +diff --git a/test/cutils/utils_pwgr/group_sample b/test/cutils/utils_pwgr/group_sample +index c73883cc..8de62df2 100644 +--- a/test/cutils/utils_pwgr/group_sample ++++ b/test/cutils/utils_pwgr/group_sample +@@ -1,3 +1,4 @@ ++root:x:a + root:x:0: + #bin:x:1: + +diff --git a/test/cutils/utils_pwgr/passwd_sample b/test/cutils/utils_pwgr/passwd_sample +index 76853454..995dea3a 100644 +--- a/test/cutils/utils_pwgr/passwd_sample ++++ b/test/cutils/utils_pwgr/passwd_sample +@@ -1,3 +1,4 @@ ++root:x:b:0: + root:x:0:0:root:/root:/bin/bash + bin:x:1:1:bin:/bin:/sbin/nologin + bin:x:-1:1:bin:/bin:/sbin/nologin +diff --git a/test/cutils/utils_pwgr/utils_pwgr_ut.cc b/test/cutils/utils_pwgr/utils_pwgr_ut.cc +index 1ed8eaa1..d856270d 100644 +--- a/test/cutils/utils_pwgr/utils_pwgr_ut.cc ++++ b/test/cutils/utils_pwgr/utils_pwgr_ut.cc +@@ -25,7 +25,10 @@ TEST(utils_pwgr, test_getpwent_r) + struct passwd pw; + struct passwd *ppw = nullptr; + struct passwd *ppw_alter = &pw; +- char buf[BUFSIZ]; ++ char buf[BUFSIZ] = { 0 }; ++ char invalid_buf[1] = { 0 }; ++ // use to get ERANGE error ++ char small_buf[10] = { 0 }; + + std::vector> testcase = { + std::make_tuple("root", "x", 0, 0, "root", "/root", "/bin/bash"), +@@ -39,7 +42,7 @@ TEST(utils_pwgr, test_getpwent_r) + + ASSERT_EQ(util_getpwent_r(NULL, &pw, buf, sizeof(buf), &ppw), -1); + ASSERT_EQ(util_getpwent_r(f_pw, &pw, NULL, 0, &ppw), -1); +- ASSERT_EQ(util_getpwent_r(f_pw, &pw, NULL, 1, &ppw), -1); ++ ASSERT_EQ(util_getpwent_r(f_pw, &pw, invalid_buf, 1, &ppw), -1); + ASSERT_EQ(util_getpwent_r(f_pw, &pw, buf, sizeof(buf), &ppw_alter), -1); + + while (!feof(f_pw)) { +@@ -48,6 +51,8 @@ TEST(utils_pwgr, test_getpwent_r) + ASSERT_EQ(util_getpwent_r(f_pw, &pw, buf, sizeof(buf), &ppw), ENOENT); + rewind(f_pw); + ++ ASSERT_EQ(util_getpwent_r(f_pw, &pw, small_buf, sizeof(small_buf), &ppw), ERANGE); ++ + for (const auto &elem : testcase) { + ASSERT_EQ(util_getpwent_r(f_pw, &pw, buf, sizeof(buf), &ppw), 0); + ASSERT_STREQ(pw.pw_name, std::get<0>(elem).c_str()); +@@ -74,7 +79,10 @@ TEST(utils_pwgr, test_getgrent_r) + struct group gr{0}; + struct group *pgr = nullptr; + struct group *pgr_alter = &gr; +- char buf[BUFSIZ]; ++ char buf[BUFSIZ] = { 0 }; ++ char invalid_buf[1] = { 0 }; ++ // use to get ERANGE error ++ char small_buf[9] = { 0 }; + size_t i = 0; + size_t j = 0; + std::vector> string_list{ +@@ -95,7 +103,7 @@ TEST(utils_pwgr, test_getgrent_r) + + ASSERT_EQ(util_getgrent_r(NULL, &gr, buf, sizeof(buf), &pgr), -1); + ASSERT_EQ(util_getgrent_r(f_gr, &gr, NULL, 0, &pgr), -1); +- ASSERT_EQ(util_getgrent_r(f_gr, &gr, NULL, 1, &pgr), -1); ++ ASSERT_EQ(util_getgrent_r(f_gr, &gr, invalid_buf, 1, &pgr), -1); + ASSERT_EQ(util_getgrent_r(f_gr, &gr, buf, sizeof(buf), &pgr_alter), -1); + + while (!feof(f_gr)) { +@@ -104,6 +112,8 @@ TEST(utils_pwgr, test_getgrent_r) + ASSERT_EQ(util_getgrent_r(f_gr, &gr, buf, sizeof(buf), &pgr), ENOENT); + rewind(f_gr); + ++ ASSERT_EQ(util_getgrent_r(f_gr, &gr, small_buf, sizeof(small_buf), &pgr), ERANGE); ++ + for (; i < string_list.size(); ++i) { + ASSERT_EQ(util_getgrent_r(f_gr, &gr, buf, sizeof(buf), &pgr), 0); + ASSERT_STREQ(gr.gr_name, std::get<0>(testcase[i]).c_str()); +@@ -113,8 +123,6 @@ TEST(utils_pwgr, test_getgrent_r) + for (j = 0; j < string_list[i].size(); ++j) { + EXPECT_TRUE(strcmp(gr.gr_mem[j], string_list[i][j].c_str()) == 0); + } +- } else { +- EXPECT_TRUE(gr.gr_mem == nullptr); + } + EXPECT_TRUE(pgr == &gr); + gr = {0}; +-- +2.20.1 + diff --git a/0015-refactor-util_getgrent_r-and-util_getpwent_r.patch b/0015-refactor-util_getgrent_r-and-util_getpwent_r.patch new file mode 100644 index 0000000..e70ee43 --- /dev/null +++ b/0015-refactor-util_getgrent_r-and-util_getpwent_r.patch @@ -0,0 +1,408 @@ +From 8da6dd20b73068e9d29fc8ed1469ade7b1dc2c12 Mon Sep 17 00:00:00 2001 +From: haozi007 +Date: Sat, 14 May 2022 09:55:18 +0100 +Subject: [PATCH 15/16] refactor util_getgrent_r and util_getpwent_r + +Signed-off-by: haozi007 +--- + src/utils/cutils/utils_pwgr.c | 215 +++++++++++------------- + test/cutils/utils_pwgr/passwd_sample | 8 +- + test/cutils/utils_pwgr/utils_pwgr_ut.cc | 8 +- + 3 files changed, 109 insertions(+), 122 deletions(-) + +diff --git a/src/utils/cutils/utils_pwgr.c b/src/utils/cutils/utils_pwgr.c +index 17cf017b..f8e4a18e 100644 +--- a/src/utils/cutils/utils_pwgr.c ++++ b/src/utils/cutils/utils_pwgr.c +@@ -29,100 +29,82 @@ + + static int hold_int(const char delim, bool required, char **src, unsigned int *dst) + { +- long long res = 0; +- char *walker = *src; ++ unsigned long long int res = 0; + char *err_str = NULL; + ++ // ensure *src not a empty string + if (**src == '\0') { + ERROR("Empty subject on given entrie is not allowed."); + return -1; + } + +- while (*walker != delim) { +- if (*walker == '\0') { +- break; +- } +- ++walker; +- } +- +- if (*walker == **src) { +- if (required) { // deafult 0 while required full content but integer part is missing +- *dst = 0; +- *src = walker + 1; +- return 0; +- } +- ERROR("Integer part is missing."); +- ++(*src); +- return -1; +- } +- +- res = strtoll(*src, &err_str, 0); +- if (err_str == *src) { +- ERROR("invalid digits string."); +- return -1; +- } ++ // covert string to long long ++ res = strtoull(*src, &err_str, 0); ++ // large digit string, return error + if (errno == ERANGE) { + ERROR("Parse int from string failed."); + return -1; + } +- if (res < 0) { +- ERROR("Gid uid shall not be negative."); +- return -1; ++ ++ // **src is not a digit ++ if (err_str == *src) { ++ if (!required) { ++ ERROR("Integer part is missing."); ++ return -1; ++ } ++ // if required, just set 0 ++ *dst = 0; ++ } else { ++ if (sizeof(void *) > 4 && res > UINT_MAX) { // make sure 64-bit platform behave same as 32-bit ++ res = UINT_MAX; ++ } ++ res = res & UINT_MAX; ++ *dst = (uint32_t)res; + } + +- if (sizeof(void *) > 4 && res > UINT_MAX) { // make sure 64-bit platform behave same as 32-bit +- res = UINT_MAX; ++ // normal case ++ if (*err_str == delim) { ++ err_str++; ++ } else if (*err_str != '\0') { ++ ERROR("Invalid digit string."); ++ return -1; + } +- res = res & UINT_MAX; +- *dst = (uint32_t)res; +- *src = err_str + 1; // update src to next valid context in line. + ++ *src = err_str; // update src to next valid context in line. + return 0; + } + +-static int hold_string(const char delim, char **src, char **dst) ++static void hold_string(const char delim, char **src, char **dst) + { +- if (**src == delim) { // if src point to deliminator, content parsing is skiped. +- *dst = ""; +- *src = *src + 1; +- return 0; +- } +- +- if (**src == '\0') { +- return 0; +- } +- + for (*dst = *src; **src != delim; ++(*src)) { + if (**src == '\0') { + break; + } + } ++ + if (**src == delim) { + **src = '\0'; + ++(*src); + } +- +- return 0; + } + + static int parse_line_pw(const char delim, char *line, struct passwd *result) + { + int ret = 0; + bool required = false; ++ char *walker = NULL; + +- ret = hold_string(delim, &line, &result->pw_name); +- if (ret != 0) { +- ERROR("Parse name error."); +- return ret; ++ walker = strpbrk(line, "\n"); ++ if (walker != NULL) { ++ // clear newline char ++ *walker = '\0'; + } + ++ hold_string(delim, &line, &result->pw_name); ++ + required = (result->pw_name[0] == '+' || result->pw_name[0] == '-') ? true : false; + +- ret = hold_string(delim, &line, &result->pw_passwd); +- if (ret != 0) { +- ERROR("Parse passwd error."); +- return ret; +- } ++ hold_string(delim, &line, &result->pw_passwd); + + ret = hold_int(delim, required, &line, &result->pw_uid); + if (ret != 0) { +@@ -130,31 +112,20 @@ static int parse_line_pw(const char delim, char *line, struct passwd *result) + ERROR("Parse uid error."); + return ret; + } ++ + ret = hold_int(delim, required, &line, &result->pw_gid); + if (ret != 0) { + // it's ok to not provide gid + ERROR("Parse gid error."); +- } +- +- ret = hold_string(delim, &line, &result->pw_gecos); +- if (ret != 0) { +- ERROR("Parse gecos error."); + return ret; + } + +- ret = hold_string(delim, &line, &result->pw_dir); +- if (ret != 0) { +- ERROR("Parse dir error."); +- return ret; +- } ++ hold_string(delim, &line, &result->pw_gecos); + +- ret = hold_string(delim, &line, &result->pw_shell); +- if (ret != 0) { +- ERROR("Parse shell error."); +- return ret; +- } ++ hold_string(delim, &line, &result->pw_dir); + +- return ret; ++ result->pw_shell = line; ++ return 0; + } + + static char **hold_string_list(char **line, char *buf_start, char *buf_end, const char terminator) +@@ -172,42 +143,38 @@ static char **hold_string_list(char **line, char *buf_start, char *buf_end, cons + walker = result; + + for (; walker < (char **)buf_end; ++walker) { +- (void)util_trim_space(*line); +- if (hold_string(',', line, walker) != 0) { +- ERROR("Parse string list error."); ++ if (**line == '\0') { + return result; + } + ++ (void)util_trim_space(*line); ++ hold_string(',', line, walker); ++ + if ((char *)(walker + 2) > buf_end) { + return NULL; + } +- +- if (**line == '\0') { +- return result; +- } + } + + return result; + } + +-static int parse_line_gr(const char delim, char *line, size_t buflen, struct group *result) ++static int parse_line_gr(const char delim, char *line, char *buffend, struct group *result) + { + int ret = 0; + bool rf = false; + char *freebuff = line + 1 + strlen(line); +- char *buffend = line + buflen; ++ char *walker = NULL; + +- ret = hold_string(delim, &line, &result->gr_name); +- if (ret != 0) { +- ERROR("Parse name error."); +- return ret; ++ walker = strpbrk(line, "\n"); ++ if (walker != NULL) { ++ // clear newline char ++ *walker = '\0'; + } + +- ret = hold_string(delim, &line, &result->gr_passwd); +- if (ret != 0) { +- ERROR("Parse gecos error."); +- return ret; +- } ++ hold_string(delim, &line, &result->gr_name); ++ ++ hold_string(delim, &line, &result->gr_passwd); ++ + if (result->gr_name[0] == '+' || result->gr_name[0] == '-') { + rf = true; + } +@@ -231,6 +198,7 @@ int util_getpwent_r(FILE *stream, struct passwd *resbuf, char *buffer, size_t bu + { + const char delim = ':'; + char *buff_end = NULL; ++ char *walker = NULL; + bool got = false; + + if (stream == NULL || resbuf == NULL || buffer == NULL || result == NULL) { +@@ -250,27 +218,36 @@ int util_getpwent_r(FILE *stream, struct passwd *resbuf, char *buffer, size_t bu + + __fsetlocking(stream, FSETLOCKING_BYCALLER); + +- if (feof(stream)) { +- *result = NULL; +- return ENOENT; +- } + buff_end = buffer + buflen - 1; ++ while (1) { ++ *buff_end = '\xff'; ++ walker = fgets(buffer, buflen, stream); ++ // if get NULL string ++ if (walker == NULL) { ++ *result = NULL; ++ // reach end of file, return error ++ if (feof(stream)) { ++ return ENOENT; ++ } ++ // overflow buffer ++ return ERANGE; ++ } ++ // just overflow last char in buffer ++ if (*buff_end != '\xff') { ++ *result = NULL; ++ return ERANGE; ++ } + +- while ((*buff_end = '\xff') && fgets(buffer, buflen, stream) != NULL) { + (void)util_trim_space(buffer); +- if (buffer[0] == '\0' || buffer[0] == '#' || strlen(buffer) < 1) { ++ // skip comment line and empty line ++ if (walker[0] == '#' || walker[0] == '\0') { + continue; + } + +- if (parse_line_pw(delim, buffer, resbuf) == 0) { ++ if (parse_line_pw(delim, walker, resbuf) == 0) { + got = true; + break; + } +- +- if (*buff_end != '\xff') { +- *result = NULL; +- return ERANGE; +- } + } + if (!got) { + *result = NULL; +@@ -286,6 +263,7 @@ int util_getgrent_r(FILE *stream, struct group *resbuf, char *buffer, size_t buf + { + const char delim = ':'; + char *buff_end = NULL; ++ char *walker = NULL; + bool got = false; + + if (stream == NULL || resbuf == NULL || buffer == NULL || result == NULL) { +@@ -305,27 +283,36 @@ int util_getgrent_r(FILE *stream, struct group *resbuf, char *buffer, size_t buf + + __fsetlocking(stream, FSETLOCKING_BYCALLER); + +- if (feof(stream)) { +- *result = NULL; +- return ENOENT; +- } + buff_end = buffer + buflen - 1; ++ while (1) { ++ *buff_end = '\xff'; ++ walker = fgets(buffer, buflen, stream); ++ // if get NULL string ++ if (walker == NULL) { ++ *result = NULL; ++ // reach end of file, return error ++ if (feof(stream)) { ++ return ENOENT; ++ } ++ // overflow buffer ++ return ERANGE; ++ } ++ // just overflow last char in buffer ++ if (*buff_end != '\xff') { ++ *result = NULL; ++ return ERANGE; ++ } + +- while ((*buff_end = '\xff') && fgets(buffer, buflen, stream) != NULL) { +- (void)util_trim_space(buffer); +- if (buffer[0] == '\0' || buffer[0] == '#' || strlen(buffer) < 1) { ++ (void)util_trim_space(walker); ++ // skip comment line and empty line ++ if (walker[0] == '#' || walker[0] == '\0') { + continue; + } + +- if (parse_line_gr(delim, buffer, buflen, resbuf) == 0) { ++ if (parse_line_gr(delim, walker, buff_end, resbuf) == 0) { + got = true; + break; + } +- +- if (*buff_end != '\xff') { +- *result = NULL; +- return ERANGE; +- } + } + + if (!got) { +diff --git a/test/cutils/utils_pwgr/passwd_sample b/test/cutils/utils_pwgr/passwd_sample +index 995dea3a..cdb1890d 100644 +--- a/test/cutils/utils_pwgr/passwd_sample ++++ b/test/cutils/utils_pwgr/passwd_sample +@@ -1,13 +1,13 @@ + root:x:b:0: + root:x:0:0:root:/root:/bin/bash +-bin:x:1:1:bin:/bin:/sbin/nologin +-bin:x:-1:1:bin:/bin:/sbin/nologin ++abin:x:1:1:bin:/bin:/sbin/nologin ++bbin:x:-1:1:bin:/bin:/sbin/nologin + uidonly:x:1::bin:/bin:/sbin/nologin + ::::1:1:bin:/bin:/sbin/nologin + root:x: + + #npt:*:66:77::/etc/ntp:/sbin/nologin +-npt:*:66:77::/etc/ntp:/sbin/nologin +-npt:*:66:77::/etc/ntp:/sbin/nologin:some:extra:context:added ++anpt:*:66:77::/etc/ntp:/sbin/nologin ++bnpt:*:66:77::/etc/ntp:/sbin/nologin:some:extra:context:added + +npt:*::::/etc/ntp:/sbin/nologin + -npt:*::::/etc/ntp:/sbin/nologin +\ No newline at end of file +diff --git a/test/cutils/utils_pwgr/utils_pwgr_ut.cc b/test/cutils/utils_pwgr/utils_pwgr_ut.cc +index d856270d..1f3dab9e 100644 +--- a/test/cutils/utils_pwgr/utils_pwgr_ut.cc ++++ b/test/cutils/utils_pwgr/utils_pwgr_ut.cc +@@ -32,10 +32,10 @@ TEST(utils_pwgr, test_getpwent_r) + + std::vector> testcase = { + std::make_tuple("root", "x", 0, 0, "root", "/root", "/bin/bash"), +- std::make_tuple("bin", "x", 1, 1, "bin", "/bin", "/sbin/nologin"), +- std::make_tuple("uidonly", "x", 1, 0, "bin", "/bin", "/sbin/nologin"), +- std::make_tuple("npt", "*", 66, 77, "", "/etc/ntp", "/sbin/nologin"), +- std::make_tuple("npt", "*", 66, 77, "", "/etc/ntp", "/sbin/nologin"), ++ std::make_tuple("abin", "x", 1, 1, "bin", "/bin", "/sbin/nologin"), ++ std::make_tuple("bbin", "x", 4294967295, 1, "bin", "/bin", "/sbin/nologin"), ++ std::make_tuple("anpt", "*", 66, 77, "", "/etc/ntp", "/sbin/nologin"), ++ std::make_tuple("bnpt", "*", 66, 77, "", "/etc/ntp", "/sbin/nologin:some:extra:context:added"), + std::make_tuple("+npt", "*", 0, 0, "", "/etc/ntp", "/sbin/nologin"), + std::make_tuple("-npt", "*", 0, 0, "", "/etc/ntp", "/sbin/nologin") + }; +-- +2.20.1 + diff --git a/0016-add-check-result-argument-ut.patch b/0016-add-check-result-argument-ut.patch new file mode 100644 index 0000000..441a75c --- /dev/null +++ b/0016-add-check-result-argument-ut.patch @@ -0,0 +1,33 @@ +From 3f02512d0b117839dce1ceb66208a96822fc7dd7 Mon Sep 17 00:00:00 2001 +From: haozi007 +Date: Mon, 16 May 2022 03:09:44 +0100 +Subject: [PATCH 16/16] add check result argument ut + +Signed-off-by: haozi007 +--- + test/cutils/utils_pwgr/utils_pwgr_ut.cc | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/test/cutils/utils_pwgr/utils_pwgr_ut.cc b/test/cutils/utils_pwgr/utils_pwgr_ut.cc +index 1f3dab9e..90d09063 100644 +--- a/test/cutils/utils_pwgr/utils_pwgr_ut.cc ++++ b/test/cutils/utils_pwgr/utils_pwgr_ut.cc +@@ -44,6 +44,7 @@ TEST(utils_pwgr, test_getpwent_r) + ASSERT_EQ(util_getpwent_r(f_pw, &pw, NULL, 0, &ppw), -1); + ASSERT_EQ(util_getpwent_r(f_pw, &pw, invalid_buf, 1, &ppw), -1); + ASSERT_EQ(util_getpwent_r(f_pw, &pw, buf, sizeof(buf), &ppw_alter), -1); ++ ASSERT_EQ(util_getpwent_r(f_pw, &pw, buf, sizeof(buf), NULL), -1); + + while (!feof(f_pw)) { + (void)getc(f_pw); +@@ -105,6 +106,7 @@ TEST(utils_pwgr, test_getgrent_r) + ASSERT_EQ(util_getgrent_r(f_gr, &gr, NULL, 0, &pgr), -1); + ASSERT_EQ(util_getgrent_r(f_gr, &gr, invalid_buf, 1, &pgr), -1); + ASSERT_EQ(util_getgrent_r(f_gr, &gr, buf, sizeof(buf), &pgr_alter), -1); ++ ASSERT_EQ(util_getgrent_r(f_gr, &gr, buf, sizeof(buf), NULL), -1); + + while (!feof(f_gr)) { + (void)getc(f_gr); +-- +2.20.1 + diff --git a/iSulad.spec b/iSulad.spec index d2e8648..046bfcb 100644 --- a/iSulad.spec +++ b/iSulad.spec @@ -1,5 +1,5 @@ %global _version 2.0.13 -%global _release 4 +%global _release 5 %global is_systemd 1 %global enable_shimv2 1 %global is_embedded 1 @@ -18,7 +18,17 @@ Patch0002: 0002-refactor-mount-parse-in-spec-module.patch Patch0003: 0003-support-isula-wait-even-if-it-s-not-oci-image.patch Patch0004: 0004-add-isula-import-restful-mode.patch Patch0005: 0005-Adapt-to-bionic-libc-parser-for-passwd-and-group-obj.patch -Patch0006: 0006-Adapt-to-bionic-libc-improve-lcov-coverage.patch +Patch0006: 0006-test-adapt-to-the-enabled-selinux-host-environment.patch +Patch0007: 0007-Adapt-to-bionic-libc-improve-lcov-coverage.patch +Patch0008: 0008-fix-cmd-isulad-shim-module-encoding-problem.patch +Patch0009: 0009-fix-utils-module-encoding-problem.patch +Patch0010: 0010-clean-the-gRPC-client-module-code.patch +Patch0011: 0011-remove-redundant-code.patch +Patch0012: 0012-fix-coding-irregularities-of-entry-module.patch +Patch0013: 0013-fix-coding-irregularities.patch +Patch0014: 0014-fix-ut-bug-and-arguments-check.patch +Patch0015: 0015-refactor-util_getgrent_r-and-util_getpwent_r.patch +Patch0016: 0016-add-check-result-argument-ut.patch %ifarch x86_64 aarch64 Provides: libhttpclient.so()(64bit) @@ -246,13 +256,19 @@ fi %endif %changelog -* Mon May 10 2022 hejunjie - 2.0.13-4 +* Mon May 16 2022 haozi007 - 2.0.13-5 +- Type: enhancement +- ID: NA +- SUG: NA +- DESC: sync from upstream openEuler/iSulad + +* Tue May 10 2022 hejunjie - 2.0.13-4 - Type: enhancement - ID: NA - SUG: NA - DESC: bionic adaptation, increase lcov coverage -* Mon May 5 2022 hejunjie - 2.0.13-3 +* Thu May 5 2022 hejunjie - 2.0.13-3 - Type: enhancement - ID: NA - SUG: NA