1 Star 0 Fork 98

Mingtai/systemd_1

forked from src-openEuler/systemd 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
backport-CVE-2022-4415-test-Add-sd_booted-condition-test-to-TEST-macro.patch 4.32 KB
一键复制 编辑 原始数据 按行查看 历史
胡宇彪 提交于 2022-12-28 09:50 . fix CVE-2022-4415
From 0578dfe3eb2ceb8571b62a904dec0ddf410f6352 Mon Sep 17 00:00:00 2001
From: Jan Janssen <medhefgo@web.de>
Date: Thu, 25 Nov 2021 10:45:15 +0100
Subject: [PATCH] test: Add sd_booted condition test to TEST macro
Note that this will only report test skips if they use TEST_RET macro.
Regular TEST macros can still be skipped, but this will not be reported
back to main();
Conflict:NA
Reference:https://github.com/systemd/systemd/commit/0578dfe3eb2ceb8571b62a904dec0ddf410f6352
---
src/shared/tests.h | 43 ++++++++++++++++++++++++++-----------------
1 file changed, 26 insertions(+), 17 deletions(-)
diff --git a/src/shared/tests.h b/src/shared/tests.h
index d1c96ef35b..95283e2829 100644
--- a/src/shared/tests.h
+++ b/src/shared/tests.h
@@ -39,7 +39,7 @@ bool can_memlock(void);
if (sd_booted() > 0) { \
x; \
} else { \
- printf("systemd not booted skipping '%s'\n", #x); \
+ printf("systemd not booted, skipping '%s'\n", #x); \
}
/* Provide a convenient way to check if we're running in CI. */
@@ -51,29 +51,31 @@ typedef struct TestFunc {
int (*int_func)(void);
} f;
const char * const name;
- bool has_ret;
+ bool has_ret:1;
+ bool sd_booted:1;
} TestFunc;
/* See static-destruct.h for an explanation of how this works. */
-#define REGISTER_TEST(func) \
+#define REGISTER_TEST(func, ...) \
_section_("SYSTEMD_TEST_TABLE") _alignptr_ _used_ _variable_no_sanitize_address_ \
static const TestFunc UNIQ_T(static_test_table_entry, UNIQ) = { \
.f = (union f) &(func), \
.name = STRINGIFY(func), \
.has_ret = __builtin_types_compatible_p(typeof((union f){}.int_func), typeof(&(func))), \
+ ##__VA_ARGS__ \
}
extern const TestFunc _weak_ __start_SYSTEMD_TEST_TABLE[];
extern const TestFunc _weak_ __stop_SYSTEMD_TEST_TABLE[];
-#define TEST(name) \
- static void test_##name(void); \
- REGISTER_TEST(test_##name); \
+#define TEST(name, ...) \
+ static void test_##name(void); \
+ REGISTER_TEST(test_##name, ##__VA_ARGS__); \
static void test_##name(void)
-#define TEST_RET(name) \
- static int test_##name(void); \
- REGISTER_TEST(test_##name); \
+#define TEST_RET(name, ...) \
+ static int test_##name(void); \
+ REGISTER_TEST(test_##name, ##__VA_ARGS__); \
static int test_##name(void)
static inline int run_test_table(void) {
@@ -84,14 +86,21 @@ static inline int run_test_table(void) {
const TestFunc *t = ALIGN_TO_PTR(__start_SYSTEMD_TEST_TABLE, sizeof(TestFunc*));
while (t < __stop_SYSTEMD_TEST_TABLE) {
- log_info("/* %s */", t->name);
-
- if (t->has_ret) {
- int r2 = t->f.int_func();
- if (r == EXIT_SUCCESS)
- r = r2;
- } else
- t->f.void_func();
+
+ if (t->sd_booted && sd_booted() <= 0) {
+ log_info("/* systemd not booted, skipping %s */", t->name);
+ if (t->has_ret && r == EXIT_SUCCESS)
+ r = EXIT_TEST_SKIP;
+ } else {
+ log_info("/* %s */", t->name);
+
+ if (t->has_ret) {
+ int r2 = t->f.int_func();
+ if (r == EXIT_SUCCESS)
+ r = r2;
+ } else
+ t->f.void_func();
+ }
t = ALIGN_TO_PTR(t + 1, sizeof(TestFunc*));
}
--
2.33.0
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/yangmingtaip/systemd_1.git
git@gitee.com:yangmingtaip/systemd_1.git
yangmingtaip
systemd_1
systemd_1
master

搜索帮助