1 Star 0 Fork 98

Mingtai/systemd_1

forked from src-openEuler/systemd 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
backport-hostname-fix-off-by-one-issue-in-gethostname.patch 1.67 KB
一键复制 编辑 原始数据 按行查看 历史
From 6a8b886fef4ad101108126cab2125a90f7aa6441 Mon Sep 17 00:00:00 2001
From: Yu Watanabe <watanabe.yu+github@gmail.com>
Date: Wed, 11 Aug 2021 00:12:40 +0900
Subject: [PATCH] hostname: fix off-by-one issue in gethostname()
gethostname() returns null-terminated hostname.
Fixes #20309 and #20417.
(cherry picked from commit ccdf235464297c2ca4c1dea8733a6bad423084d5)
Conflict:NA
Reference:https://github.com/systemd/systemd/commit/6a8b886fef4ad101108126cab2125a90f7aa6441
---
src/shared/hostname-setup.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/shared/hostname-setup.c b/src/shared/hostname-setup.c
index 511aa7d031..742174d6c8 100644
--- a/src/shared/hostname-setup.c
+++ b/src/shared/hostname-setup.c
@@ -20,11 +20,11 @@
#include "util.h"
static int sethostname_idempotent_full(const char *s, bool really) {
- char buf[HOST_NAME_MAX + 1] = {};
+ char buf[HOST_NAME_MAX + 1];
assert(s);
- if (gethostname(buf, sizeof(buf) - 1) < 0)
+ if (gethostname(buf, sizeof(buf)) < 0)
return -errno;
if (streq(buf, s))
@@ -42,11 +42,11 @@ int sethostname_idempotent(const char *s) {
}
bool get_hostname_filtered(char ret[static HOST_NAME_MAX + 1]) {
- char buf[HOST_NAME_MAX + 1] = {};
+ char buf[HOST_NAME_MAX + 1];
/* Returns true if we got a good hostname, false otherwise. */
- if (gethostname(buf, sizeof(buf) - 1) < 0)
+ if (gethostname(buf, sizeof(buf)) < 0)
return false; /* This can realistically only fail with ENAMETOOLONG.
* Let's treat that case the same as an invalid hostname. */
--
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

搜索帮助