Skip to content

Commit

Permalink
Fix NULL checks and incorrect inits
Browse files Browse the repository at this point in the history
  • Loading branch information
Rot127 committed Oct 22, 2024
1 parent 4231929 commit c2423f2
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 27 deletions.
42 changes: 22 additions & 20 deletions librz/arch/analysis.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <rz_analysis.h>
#include <rz_util.h>
#include <rz_list.h>
#include <rz_util/rz_assert.h>
#include <rz_util/rz_path.h>
#include <rz_arch.h>
#include <rz_lib.h>
Expand Down Expand Up @@ -211,32 +212,33 @@ RZ_API bool rz_analysis_plugin_del(RzAnalysis *analysis, RZ_NONNULL RzAnalysisPl
}

RZ_API bool rz_analysis_use(RzAnalysis *analysis, const char *name) {
rz_return_val_if_fail(analysis && name, false);
if (analysis->cur && !strcmp(analysis->cur->name, name)) {
return true;
}

RzIterator *it = ht_sp_as_iter(analysis->plugins);
RzAnalysisPlugin **val;

if (analysis) {
if (analysis->cur && !strcmp(analysis->cur->name, name)) {
return true;
rz_iterator_foreach(it, val) {
RzAnalysisPlugin *h = *val;
if (!h || !h->name || strcmp(h->name, name)) {
continue;
}
rz_iterator_foreach(it, val) {
RzAnalysisPlugin *h = *val;
if (!h || !h->name || strcmp(h->name, name)) {
continue;
}
plugin_fini(analysis);
analysis->cur = h;
if (h->init && !h->init(&analysis->plugin_data)) {
RZ_LOG_ERROR("analysis plugin '%s' failed to initialize.\n", h->name);
return false;
}
rz_analysis_set_reg_profile(analysis);
if (analysis->il_vm) {
rz_analysis_il_vm_setup(analysis);
}
return true;
plugin_fini(analysis);
analysis->cur = h;
if (h->init && !h->init(&analysis->plugin_data)) {
RZ_LOG_ERROR("analysis plugin '%s' failed to initialize.\n", h->name);
rz_iterator_free(it);
return false;
}
rz_analysis_set_reg_profile(analysis);
if (analysis->il_vm) {
rz_analysis_il_vm_setup(analysis);
}
rz_iterator_free(it);
return true;
}
rz_iterator_free(it);
return false;
}

Expand Down
14 changes: 8 additions & 6 deletions librz/arch/asm.c
Original file line number Diff line number Diff line change
Expand Up @@ -393,17 +393,19 @@ RZ_API bool rz_asm_is_valid(RzAsm *a, const char *name) {
}

RZ_API bool rz_asm_use_assembler(RzAsm *a, const char *name) {
RzAsmPlugin *h;
RzIterator *iter = ht_sp_as_iter(a->plugins);
if (!a) {
return false;
}
if (!(name && *name)) {
a->acur = NULL;
}
rz_iterator_foreach(iter, h) {
RzIterator *iter = ht_sp_as_iter(a->plugins);
RzAsmPlugin **val;
rz_iterator_foreach(iter, val) {
RzAsmPlugin *h = *val;
if (h->assemble && !strcmp(h->name, name)) {
a->acur = h;
rz_iterator_free(iter);
return true;
}
}
Expand Down Expand Up @@ -449,12 +451,12 @@ RZ_API bool rz_asm_use(RzAsm *a, RZ_NULLABLE const char *name) {
if (!name) {
return false;
}
RzIterator *iter = ht_sp_as_iter(a->plugins);
RzAsmPlugin **val;
RzCore *core = a->core;
if (a->cur && !strcmp(a->cur->arch, name)) {
return true;
}
RzIterator *iter = ht_sp_as_iter(a->plugins);
RzAsmPlugin **val;
RzCore *core = a->core;
rz_iterator_foreach(iter, val) {
RzAsmPlugin *h = *val;
if (h->arch && h->name && !strcmp(h->name, name)) {
Expand Down
2 changes: 1 addition & 1 deletion librz/bin/bin.c
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ RZ_API RzBin *rz_bin_new(void) {
/* extractors */
bin->binxtrs = ht_sp_new(HT_STR_DUP, NULL, NULL);
for (size_t i = 0; i < RZ_ARRAY_SIZE(bin_xtr_static_plugins); ++i) {
ht_sp_insert(bin->plugins, bin_xtr_static_plugins[i]->name, bin_xtr_static_plugins[i]);
ht_sp_insert(bin->binxtrs, bin_xtr_static_plugins[i]->name, bin_xtr_static_plugins[i]);
}

return bin;
Expand Down

0 comments on commit c2423f2

Please sign in to comment.