1 Star 0 Fork 43

wangjunqiang / kpatch

forked from src-openEuler / kpatch 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0026-kpatch-build-Add-missing-allocation-failure-checks.patch 2.23 KB
一键复制 编辑 原始数据 按行查看 历史
谢志鹏 提交于 2022-01-26 15:25 . backport upstream patches
From e06664f379eab0b3f80c504c6656f805bba30e69 Mon Sep 17 00:00:00 2001
From: David Vernet <void@manifault.com>
Date: Thu, 13 Jan 2022 12:57:15 -0800
Subject: [PATCH] kpatch-build: Add missing allocation failure checks
In kpatch-build, there are a number of places where a dynamic allocation
is performed, but the allocation is not checked for a failure. The
common pattern in kpatch-build is to check whether the returned pointer
is NULL, and if so, invoke the ERROR() macro to print a message and
abort the program.
kpatch_create_mcount_sections(), CORRELATE_ELEMENT(), and
create_klp_arch_sections() all had dynamic allocations without failure
checks. This diff adjusts those callsites to properly check for a failed
allocation, and ERROR() accordingly.
Signed-off-by: David Vernet <void@manifault.com>
---
kpatch-build/create-diff-object.c | 4 ++++
kpatch-build/create-klp-module.c | 2 ++
2 files changed, 6 insertions(+)
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
index 442d8f8..01e5d63 100644
--- a/kpatch-build/create-diff-object.c
+++ b/kpatch-build/create-diff-object.c
@@ -979,6 +979,8 @@ do { \
log_debug("renaming %s %s to %s\n", \
kindstr, e2->name, e1->name); \
e2->name = strdup(e1->name); \
+ if (!e2->name) \
+ ERROR("strdup"); \
} \
} while (0)
@@ -3688,6 +3690,8 @@ static void kpatch_create_mcount_sections(struct kpatch_elf *kelf)
/* Make a writable copy of the text section data */
newdata = malloc(sym->sec->data->d_size);
+ if (!newdata)
+ ERROR("malloc");
memcpy(newdata, sym->sec->data->d_buf, sym->sec->data->d_size);
sym->sec->data->d_buf = newdata;
insn = newdata;
diff --git a/kpatch-build/create-klp-module.c b/kpatch-build/create-klp-module.c
index 547e587..8ceb8f3 100644
--- a/kpatch-build/create-klp-module.c
+++ b/kpatch-build/create-klp-module.c
@@ -343,6 +343,8 @@ static void create_klp_arch_sections(struct kpatch_elf *kelf, char *strings)
new_size = old_size + base->data->d_size;
sec->data->d_buf = realloc(sec->data->d_buf, new_size);
+ if (!sec->data->d_buf)
+ ERROR("realloc");
sec->data->d_size = new_size;
sec->sh.sh_size = sec->data->d_size;
memcpy(sec->data->d_buf + old_size,
--
2.27.0
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/geasscore/kpatch.git
git@gitee.com:geasscore/kpatch.git
geasscore
kpatch
kpatch
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891