Skip to content

Commit

Permalink
Force usage of RzList methods instead of direct access of the fields (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
wargio committed Dec 18, 2023
1 parent 770084c commit 8fba9b4
Show file tree
Hide file tree
Showing 42 changed files with 521 additions and 375 deletions.
14 changes: 6 additions & 8 deletions librz/analysis/block.c
Original file line number Diff line number Diff line change
Expand Up @@ -807,10 +807,8 @@ RZ_API RzAnalysisBlock *rz_analysis_block_chop_noreturn(RzAnalysisBlock *block,

// This last step isn't really critical, but nice to have.
// Prepare to merge blocks with their predecessors if possible
RzList merge_blocks;
rz_list_init(&merge_blocks);
merge_blocks.free = (RzListFree)rz_analysis_block_unref;
ht_up_foreach(succs, noreturn_get_blocks_cb, &merge_blocks);
RzList *merge_blocks = rz_list_newf((RzListFree)rz_analysis_block_unref);
ht_up_foreach(succs, noreturn_get_blocks_cb, merge_blocks);

// Free/unref BEFORE doing the merge!
// Some of the blocks might not be valid anymore later!
Expand All @@ -820,19 +818,19 @@ RZ_API RzAnalysisBlock *rz_analysis_block_chop_noreturn(RzAnalysisBlock *block,
ut64 block_addr = block->addr; // save the addr to identify the block. the automerge might free it so we must not use the pointer!

// Do the actual merge
rz_analysis_block_automerge(&merge_blocks);
rz_analysis_block_automerge(merge_blocks);

// No try to recover the pointer to the block if it still exists
RzAnalysisBlock *ret = NULL;
for (it = merge_blocks.head; it && (block = it->data, 1); it = it->n) {
rz_list_foreach (merge_blocks, it, block) {
if (block->addr == block_addr) {
// block is still there
ret = block;
break;
}
}

rz_list_purge(&merge_blocks);
rz_list_free(merge_blocks);
return ret;
}

Expand Down Expand Up @@ -941,7 +939,7 @@ RZ_API void rz_analysis_block_automerge(RzList /*<RzAnalysisBlock *>*/ *blocks)
// we would uaf after the merge since block will be freed.
RzListIter *bit;
RzAnalysisBlock *clock;
for (bit = it->n; bit && (clock = bit->data, 1); bit = bit->n) {
rz_list_foreach_iter(rz_list_iter_get_next(it), bit, clock) {
RzAnalysisBlock *fixup_pred = ht_up_find(ctx.predecessors, (ut64)(size_t)clock, NULL);
if (fixup_pred == block) {
rz_list_push(fixup_candidates, clock);
Expand Down
2 changes: 1 addition & 1 deletion librz/analysis/var.c
Original file line number Diff line number Diff line change
Expand Up @@ -1758,7 +1758,7 @@ RZ_API char *rz_analysis_fcn_format_sig(RZ_NONNULL RzAnalysis *analysis, RZ_NONN
size_t tmp_len = strlen(vartype);
rz_strbuf_appendf(buf, "%s%s%s%s", vartype,
tmp_len && vartype[tmp_len - 1] == '*' ? "" : " ",
var->name, iter->n ? ", " : "");
var->name, rz_list_iter_has_next(iter) ? ", " : "");
free(vartype);
}

Expand Down
6 changes: 2 additions & 4 deletions librz/asm/asm.c
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,7 @@ static void set_plugin_configs(RZ_BORROW RzAsm *rz_asm, RZ_BORROW RzConfig *pcfg
RzConfig *conf = ((RzCore *)(rz_asm->core))->config;
RzConfigNode *n;
RzListIter *it;
rz_list_foreach_iter(pcfg->nodes, it) {
n = it->data;
rz_list_foreach (pcfg->nodes, it, n) {
if (!rz_config_add_node(conf, rz_config_node_clone(n))) {
RZ_LOG_WARN("Failed to add \"%s\" to the global config.\n", n->name)
}
Expand All @@ -418,8 +417,7 @@ static void unset_plugins_config(RZ_BORROW RzAsm *rz_asm, RZ_BORROW RzConfig *pc
RzConfig *conf = ((RzCore *)(rz_asm->core))->config;
RzConfigNode *n;
RzListIter *it;
rz_list_foreach_iter(pcfg->nodes, it) {
n = it->data;
rz_list_foreach (pcfg->nodes, it, n) {
if (!rz_config_rm(conf, n->name)) {
RZ_LOG_WARN("Failed to remove \"%s\" from the global config.", n->name)
}
Expand Down
2 changes: 1 addition & 1 deletion librz/bin/format/le/le.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ static RZ_BORROW RzBinSymbol *le_add_symbol(rz_bin_le_obj_t *bin, ut32 ordinal,
if (rz_list_empty(bin->symbols)) {
ordinal = 1;
} else {
ordinal = ((RzBinSymbol *)rz_list_tail(bin->symbols)->data)->ordinal + 1;
ordinal = ((RzBinSymbol *)rz_list_get_tail_data(bin->symbols))->ordinal + 1;
}
}
if (!rz_list_append(bin->symbols, sym)) {
Expand Down
5 changes: 3 additions & 2 deletions librz/bin/format/mach0/dyldcache.c
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ static void match_bin_entries(RzDyldCache *cache, void *entries) {
if (!it) {
break;
}
bin = it->data;
bin = rz_list_iter_get_data(it);
if (!bin) {
break;
}
Expand All @@ -521,7 +521,8 @@ static void match_bin_entries(RzDyldCache *cache, void *entries) {
bin->nlist_start_index = e->nlistStartIndex;
bin->nlist_count = e->nlistCount;
}
it = it->n;

it = rz_list_iter_get_next(it);
}
}

Expand Down
2 changes: 1 addition & 1 deletion librz/bin/format/mz/mz.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ RzList /*<RzBinSection *>*/ *rz_bin_mz_get_segments(const struct rz_bin_mz_obj_t
rz_list_foreach (seg_list, iter, section) {
section->name = rz_str_newf("seg_%03d", section_number);
if (section_number) {
RzBinSection *p_section = iter->p->data;
RzBinSection *p_section = rz_list_iter_get_prev_data(iter);
p_section->size = section->vaddr - p_section->vaddr;
p_section->vsize = p_section->size;
}
Expand Down
16 changes: 9 additions & 7 deletions librz/bin/format/pe/pe_clr.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,17 @@ RZ_OWN RzList /*<RzBinSymbol *>*/ *PE_(rz_bin_pe_get_clr_symbols)(RzBinPEObj *bi
ut32 type_methods_end = type_methods_start;

if (type_it) {
Pe_image_metadata_typedef *typedef_ = type_it->data;
Pe_image_metadata_typedef *typedef_ = rz_list_iter_get_data(type_it);
type_name = rz_buf_get_string(bin->clr->strings, typedef_->name);
type_namespace = rz_buf_get_string(bin->clr->strings, typedef_->namespace);

type_methods_start = ((Pe_image_metadata_typedef *)type_it->data)->methodlist;
type_methods_start = typedef_->methodlist;
type_methods_end = rz_pvector_len(bin->clr->methoddefs) + 1;

type_it = type_it->n;
type_it = rz_list_iter_get_next(type_it);
if (type_it) {
type_methods_end = ((Pe_image_metadata_typedef *)type_it->data)->methodlist;
Pe_image_metadata_typedef *itypedef_ = rz_list_iter_get_data(type_it);
type_methods_end = itypedef_->methodlist;
}
}

Expand All @@ -54,14 +55,15 @@ RZ_OWN RzList /*<RzBinSymbol *>*/ *PE_(rz_bin_pe_get_clr_symbols)(RzBinPEObj *bi
free(type_name);
free(type_namespace);

Pe_image_metadata_typedef *typedef_ = type_it->data;
Pe_image_metadata_typedef *typedef_ = rz_list_iter_get_data(type_it);
type_name = rz_buf_get_string(bin->clr->strings, typedef_->name);
type_namespace = rz_buf_get_string(bin->clr->strings, typedef_->namespace);

// Update next end
type_it = type_it->n;
type_it = rz_list_iter_get_next(type_it);
if (type_it) {
type_methods_end = ((Pe_image_metadata_typedef *)type_it->data)->methodlist;
Pe_image_metadata_typedef *next_typedef_ = rz_list_iter_get_data(type_it);
type_methods_end = next_typedef_->methodlist;
} else {
type_methods_end = rz_pvector_len(bin->clr->methoddefs) + 1;
}
Expand Down
6 changes: 4 additions & 2 deletions librz/bin/format/pyc/marshal.c
Original file line number Diff line number Diff line change
Expand Up @@ -1151,8 +1151,10 @@ static pyc_object *get_object(RzBinPycObj *pyc, RzBuffer *buffer) {
}

if (flag && ref_idx) {
free_object(ref_idx->data);
ref_idx->data = copy_object(ret);
void *p = rz_list_iter_get_data(ref_idx);
free_object(p);
p = copy_object(ret);
rz_list_iter_set_data(ref_idx, p);
}
return ret;
}
Expand Down
Loading

0 comments on commit 8fba9b4

Please sign in to comment.