8 Star 0 Fork 50

src-anolis-os/systemd

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0180-tree-wide-various-ubsan-zero-size-memory-fixes.patch 2.27 KB
一键复制 编辑 原始数据 按行查看 历史
张彬琛 提交于 2021-01-20 13:59 . import systemd-239-29.el8.src.rpm
From 6bb1d52f0554f687ef27de46c0b9daac9d256d60 Mon Sep 17 00:00:00 2001
From: Lennart Poettering <lennart@poettering.net>
Date: Wed, 10 Oct 2018 11:34:30 +0200
Subject: [PATCH] tree-wide: various ubsan zero size memory fixes
Fixes: #10346
(cherry picked from commit 65f95765d05ddcd9e5849b68c379afa7e87d1248)
Resolves: #1683319
---
src/basic/bitmap.c | 2 +-
src/basic/util.h | 8 +++++++-
src/test/test-hexdecoct.c | 2 +-
3 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/src/basic/bitmap.c b/src/basic/bitmap.c
index c17c6a7a02..a4cd6451b0 100644
--- a/src/basic/bitmap.c
+++ b/src/basic/bitmap.c
@@ -206,7 +206,7 @@ bool bitmap_equal(Bitmap *a, Bitmap *b) {
return true;
common_n_bitmaps = MIN(a->n_bitmaps, b->n_bitmaps);
- if (memcmp(a->bitmaps, b->bitmaps, sizeof(uint64_t) * common_n_bitmaps) != 0)
+ if (memcmp_safe(a->bitmaps, b->bitmaps, sizeof(uint64_t) * common_n_bitmaps) != 0)
return false;
c = a->n_bitmaps > b->n_bitmaps ? a : b;
diff --git a/src/basic/util.h b/src/basic/util.h
index b68ef25ed8..4659a21b06 100644
--- a/src/basic/util.h
+++ b/src/basic/util.h
@@ -134,7 +134,13 @@ static inline int memcmp_safe(const void *s1, const void *s2, size_t n) {
int on_ac_power(void);
-#define memzero(x,l) (memset((x), 0, (l)))
+#define memzero(x,l) \
+ ({ \
+ size_t _l_ = (l); \
+ void *_x_ = (x); \
+ _l_ == 0 ? _x_ : memset(_x_, 0, _l_); \
+ })
+
#define zero(x) (memzero(&(x), sizeof(x)))
static inline void *mempset(void *s, int c, size_t n) {
diff --git a/src/test/test-hexdecoct.c b/src/test/test-hexdecoct.c
index da9f3008bb..a972ddcef7 100644
--- a/src/test/test-hexdecoct.c
+++ b/src/test/test-hexdecoct.c
@@ -84,7 +84,7 @@ static void test_unhexmem_one(const char *s, size_t l, int retval) {
l = strlen(s);
assert_se(hex = hexmem(mem, len));
- answer = strndupa(s, l);
+ answer = strndupa(s ?: "", l);
assert_se(streq(delete_chars(answer, WHITESPACE), hex));
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/src-anolis-os/systemd.git
git@gitee.com:src-anolis-os/systemd.git
src-anolis-os
systemd
systemd
a8

搜索帮助