From 3ad7429fc67b36c5aaf880f10da19d476cbf724c Mon Sep 17 00:00:00 2001 From: renoseven Date: Mon, 18 Aug 2025 16:50:34 +0800 Subject: [PATCH] upatch-manage: fix access invalid pointer issue Signed-off-by: renoseven --- upatch-manage/patch_entity.h | 5 +++-- upatch-manage/patch_manage.c | 1 + upatch-manage/process_entity.h | 7 ++++--- upatch-manage/target_entity.h | 5 +++-- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/upatch-manage/patch_entity.h b/upatch-manage/patch_entity.h index 6035aac..1f4be06 100644 --- a/upatch-manage/patch_entity.h +++ b/upatch-manage/patch_entity.h @@ -22,6 +22,7 @@ #define _UPATCH_MANAGE_PATCH_ENTITY_H #include +#include #include #include #include @@ -145,7 +146,7 @@ void release_patch(struct kref *kref); */ static inline struct patch_entity *get_patch(struct patch_entity *patch) { - if (unlikely(!patch)) { + if (unlikely(IS_ERR_OR_NULL(patch))) { return NULL; } @@ -162,7 +163,7 @@ static inline struct patch_entity *get_patch(struct patch_entity *patch) */ static inline void put_patch(struct patch_entity *patch) { - if (unlikely(!patch)) { + if (unlikely(IS_ERR_OR_NULL(patch))) { return; } diff --git a/upatch-manage/patch_manage.c b/upatch-manage/patch_manage.c index c0e238a..12409f1 100644 --- a/upatch-manage/patch_manage.c +++ b/upatch-manage/patch_manage.c @@ -239,6 +239,7 @@ int upatch_load(const char *target_file, const char *patch_file) new_target = load_target(file); if (unlikely(IS_ERR(new_target))) { ret = PTR_ERR(new_target); + new_target = NULL; log_err("failed to load target %s, ret=%d\n", target_file, ret); goto release_out; } diff --git a/upatch-manage/process_entity.h b/upatch-manage/process_entity.h index de6635a..53f172e 100644 --- a/upatch-manage/process_entity.h +++ b/upatch-manage/process_entity.h @@ -22,7 +22,8 @@ #define _UPATCH_MANAGE_PROCESS_ENTITY_H #include -#include +#include + #include #include #include @@ -112,7 +113,7 @@ void release_process(struct kref *kref); */ static inline struct process_entity *get_process(struct process_entity *process) { - if (unlikely(!process)) { + if (unlikely(IS_ERR_OR_NULL(process))) { return NULL; } @@ -129,7 +130,7 @@ static inline struct process_entity *get_process(struct process_entity *process) */ static inline void put_process(struct process_entity *process) { - if (unlikely(!process)) { + if (unlikely(IS_ERR_OR_NULL(process))) { return; } diff --git a/upatch-manage/target_entity.h b/upatch-manage/target_entity.h index 7c0b96c..6f07f84 100644 --- a/upatch-manage/target_entity.h +++ b/upatch-manage/target_entity.h @@ -23,6 +23,7 @@ #include #include +#include #include #include @@ -150,7 +151,7 @@ void release_target(struct kref *kref); */ static inline struct target_entity *get_target(struct target_entity *target) { - if (unlikely(!target)) { + if (unlikely(IS_ERR_OR_NULL(target))) { return NULL; } @@ -167,7 +168,7 @@ static inline struct target_entity *get_target(struct target_entity *target) */ static inline void put_target(struct target_entity *target) { - if (unlikely(!target)) { + if (unlikely(IS_ERR_OR_NULL(target))) { return; } -- Gitee