1 Star 0 Fork 49

wangkaiyuan/systemd

forked from src-anolis-os/systemd 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0759-sd-bus-switch-to-a-manual-overflow-check-in-sd_bus_t.patch 2.00 KB
一键复制 编辑 原始数据 按行查看 历史
小龙 提交于 2023-01-12 18:39 . update to systemd-239-68.el8_7.1
From 598eecf5c1c948535ca626833bc5cea59060913f Mon Sep 17 00:00:00 2001
From: Lennart Poettering <lennart@poettering.net>
Date: Wed, 20 Apr 2022 22:30:22 +0200
Subject: [PATCH] sd-bus: switch to a manual overflow check in
sd_bus_track_add_name()
This is generally used in a directly client controllable way, hence we
should handle ref count overflow gracefully, instead of hitting an
assert().
As discussed:
https://github.com/systemd/systemd/pull/23099#discussion_r854341850
(cherry picked from commit 7f40cb7c86b0fff3a82096a9499570bad9c19fd2)
[msekleta: We've never switched to using track_item_ref/unref introduced
in c2d7dd35d2 hence we still had potential undefined behavior related to
overflow check and this commit fixes that.]
Related: #2047373
---
src/libsystemd/sd-bus/bus-track.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/src/libsystemd/sd-bus/bus-track.c b/src/libsystemd/sd-bus/bus-track.c
index 8893f190a1..b818e93bec 100644
--- a/src/libsystemd/sd-bus/bus-track.c
+++ b/src/libsystemd/sd-bus/bus-track.c
@@ -208,12 +208,16 @@ _public_ int sd_bus_track_add_name(sd_bus_track *track, const char *name) {
i = hashmap_get(track->names, name);
if (i) {
if (track->recursive) {
- unsigned k = i->n_ref + 1;
+ assert(i->n_ref > 0);
- if (k < i->n_ref) /* Check for overflow */
+ /* Manual oveflow check (instead of a DEFINE_TRIVIAL_REF_FUNC() helper or so), so
+ * that we can return a proper error, given this is almost always called in a
+ * directly client controllable way, and thus better should never hit an assertion
+ * here. */
+ if (i->n_ref >= UINT_MAX)
return -EOVERFLOW;
- i->n_ref = k;
+ i->n_ref++;
}
bus_track_remove_from_queue(track);
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wangkaiyuan01/systemd.git
git@gitee.com:wangkaiyuan01/systemd.git
wangkaiyuan01
systemd
systemd
a8

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385