From 489bc4c140096004a8775f572b4cd3b420f5da06 Mon Sep 17 00:00:00 2001 From: Rong Tao Date: Fri, 8 Mar 2024 11:25:21 +0800 Subject: [PATCH] ulpatch: Fix segvfault $ ulpatch -p $(pidof hello) --patch patch-add-vars.ulp.no-build-id --lv=dbg -v 11:20:59 [DEBUG][ehdr.c ehdr_magic_ok:20] Wrong ELF magic 11:20:59 [ERROR][patch.c setup_load_info:370] Not found Build ID or .note.gnu.build-id section. Add gcc argument '-Wl,--build-id=sha1' or Add linker(ld) argument '--build-id=sha1' 11:20:59 [DEBUG][ulpatch.c check_patch_file:147] Load patch-add-vars.ulp.no-build-id failed munmap_chunk(): invalid pointer Aborted (core dumped) Signed-off-by: Rong Tao --- src/patch/patch.c | 2 ++ src/ulpatch.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/patch/patch.c b/src/patch/patch.c index 3ea55d5d..83c3e3f1 100644 --- a/src/patch/patch.c +++ b/src/patch/patch.c @@ -73,6 +73,7 @@ void release_load_info(struct load_info *info) free(info->str_build_id); info->str_build_id = NULL; } + if (info->ulp_name) { free(info->ulp_name); info->ulp_name = NULL; @@ -890,6 +891,7 @@ int init_patch(struct task_struct *task, const char *obj_file) struct load_info info = { .target_task = task, + .str_build_id = NULL, }; if (!(task->fto_flag & FTO_PROC)) { diff --git a/src/ulpatch.c b/src/ulpatch.c index db1f331f..557b41bb 100644 --- a/src/ulpatch.c +++ b/src/ulpatch.c @@ -127,7 +127,7 @@ static int parse_config(int argc, char *argv[]) int check_patch_file(const char *file) { int err = 0; - struct load_info info; + struct load_info info = {0}; if (!file) return -EEXIST;