From d49ae4b3ff06087f829b19aa2a2c504c08ab75ef Mon Sep 17 00:00:00 2001 From: astralia Date: Thu, 14 Nov 2024 01:22:33 +0100 Subject: [PATCH] Check esil_cfg and esil_dfg APIs nullability for #23490 --- libr/anal/esil_cfg.c | 13 +++++++------ libr/anal/esil_dfg.c | 20 ++++++++------------ 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/libr/anal/esil_cfg.c b/libr/anal/esil_cfg.c index 861fae1219e72..dd26e5b78c98e 100644 --- a/libr/anal/esil_cfg.c +++ b/libr/anal/esil_cfg.c @@ -1,10 +1,10 @@ -/* radare2 - LGPL - Copyright 2019 - condret */ +/* radare2 - LGPL - Copyright 2019 - 2024 - condret */ #include #include #include -/* shared internal state of the subgraph generating functions */ +/* shared internal state of the subgraph generating functions */ typedef struct esil_cfg_generator_t { REsil *esil; @@ -52,7 +52,7 @@ typedef struct esil_value_t { EsilValType type; } EsilVal; -/* HELPERS */ +/* HELPERS */ // r_str_tok () ? static char *condrets_strtok(char *str, const char tok) { @@ -157,7 +157,7 @@ void _handle_if_enter (EsilCfgGen *gen, ut32 id, const bool has_next) { EsilCfgScopeCookie *cookie = R_NEW0 (EsilCfgScopeCookie); // get current bb - // REsilBB *bb = (REsilBB *)gen->cur->data; + // REsilBB *bb = (REsilBB *)gen->cur->data; // create if-enter-bb REsilBB *entered_bb = R_NEW0 (REsilBB); @@ -571,8 +571,9 @@ R_API RAnalEsilCFG *r_anal_esil_cfg_expr(RAnalEsilCFG *cfg, RAnal *anal, const u return ret; } -R_API RAnalEsilCFG *r_anal_esil_cfg_op(RAnalEsilCFG *cfg, RAnal *anal, RAnalOp *op) { - if (!op || !anal || !anal->reg || !anal->esil) { +R_API RAnalEsilCFG *r_anal_esil_cfg_op(R_NULLABLE RAnalEsilCFG *cfg, RAnal *anal, RAnalOp *op) { + R_RETURN_VAL_IF_FAIL (anal && op, NULL); + if (!anal->reg || !anal->esil) { return NULL; } REsilBB *glue_bb = R_NEW0 (REsilBB); diff --git a/libr/anal/esil_dfg.c b/libr/anal/esil_dfg.c index 41f2dd373e47d..83d8e225f5088 100644 --- a/libr/anal/esil_dfg.c +++ b/libr/anal/esil_dfg.c @@ -1,4 +1,4 @@ -/* radare - LGPL - Copyright 2019-2023 - condret */ +/* radare - LGPL - Copyright 2019-2024 - condret */ #include @@ -30,7 +30,8 @@ typedef struct r_anal_esil_dfg_const_reducer_t { // TODO: simple const propagation - use node->type of srcs to propagate consts of pushed vars -R_API RAnalEsilDFGNode *r_anal_esil_dfg_node_new(RAnalEsilDFG *edf, const char *c) { +R_API RAnalEsilDFGNode *r_anal_esil_dfg_node_new(RAnalEsilDFG *edf, R_NULLABLE const char *c) { + R_RETURN_VAL_IF_FAIL (edf, NULL); RAnalEsilDFGNode *ret = R_NEW0 (RAnalEsilDFGNode); ret->content = r_strbuf_new (c); ret->idx = edf->idx++; @@ -1640,10 +1641,9 @@ R_API void r_anal_esil_dfg_free(RAnalEsilDFG *dfg) { } } -R_API RAnalEsilDFG *r_anal_esil_dfg_expr(RAnal *anal, RAnalEsilDFG *dfg, const char *expr, bool use_map_info, bool use_maps) { - if (!expr) { - return NULL; - } +R_API RAnalEsilDFG *r_anal_esil_dfg_expr(RAnal *anal, R_NULLABLE RAnalEsilDFG *dfg, const char *expr, + bool use_map_info, bool use_maps) { + R_RETURN_VAL_IF_FAIL (anal && expr, NULL); REsil *esil = r_esil_new (4096, 0, 1); if (!esil) { return NULL; @@ -2073,18 +2073,14 @@ R_API void r_anal_esil_dfg_fold_const(RAnal *anal, RAnalEsilDFG *dfg) { } R_API RStrBuf *r_anal_esil_dfg_filter(RAnalEsilDFG *dfg, const char *reg) { - if (!dfg || !reg) { - return NULL; - } + R_RETURN_VAL_IF_FAIL (dfg && reg, NULL); RGraphNode *resolve_me = _edf_reg_get (dfg, reg); return resolve_me? filter_gnode_expr (dfg, resolve_me): NULL; } R_API RStrBuf *r_anal_esil_dfg_filter_expr(RAnal *anal, const char *expr, const char *reg, bool use_map_info, bool use_maps) { - if (!reg) { - return NULL; - } + R_RETURN_VAL_IF_FAIL (anal && expr && reg, NULL); RAnalEsilDFG *dfg = r_anal_esil_dfg_expr (anal, NULL, expr, use_map_info, use_maps); if (!dfg) { return NULL;