Skip to content

Commit

Permalink
Check esil_cfg and esil_dfg APIs nullability for #23490
Browse files Browse the repository at this point in the history
  • Loading branch information
astralia authored and trufae committed Nov 14, 2024
1 parent cb4bce0 commit d7d78c9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
13 changes: 7 additions & 6 deletions libr/anal/esil_cfg.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* radare2 - LGPL - Copyright 2019 - condret */
/* radare2 - LGPL - Copyright 2019 - 2024 - condret */

#include <r_types.h>
#include <r_util.h>
#include <r_anal.h>

/* shared internal state of the subgraph generating functions */
/* shared internal state of the subgraph generating functions */

typedef struct esil_cfg_generator_t {
REsil *esil;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
20 changes: 8 additions & 12 deletions libr/anal/esil_dfg.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2019-2023 - condret */
/* radare - LGPL - Copyright 2019-2024 - condret */

#include <r_anal.h>

Expand Down Expand Up @@ -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) {

This comment has been minimized.

Copy link
@condret

condret Nov 14, 2024

Member

I disagree with this nullable. though passing NULL would not cause any crash, this should not be marked as explicitly nullable

This comment has been minimized.

Copy link
@trufae

trufae Nov 14, 2024

Collaborator

So you want it nullable or non nullable because the behaviour in the code is the one you are expecting unless i missunderstood.

This comment has been minimized.

Copy link
@condret

condret Nov 15, 2024

Member

I think i got this wrong

R_RETURN_VAL_IF_FAIL (edf, NULL);
RAnalEsilDFGNode *ret = R_NEW0 (RAnalEsilDFGNode);
ret->content = r_strbuf_new (c);
ret->idx = edf->idx++;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit d7d78c9

Please sign in to comment.