Skip to content

Commit

Permalink
Move Lib already loaded check before dlopen Call (#15075) ##core
Browse files Browse the repository at this point in the history
  • Loading branch information
thestr4ng3r authored and radare committed Sep 19, 2019
1 parent dd74f86 commit 0b9edb4
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions libr/util/lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,33 @@ R_API int r_lib_close(RLib *lib, const char *file) {
return -1;
}

static bool __already_loaded(RLib *lib, const char *file) {
const char *fileName = r_str_rstr (file, R_SYS_DIR);
RLibPlugin *p;
RListIter *iter;
if (fileName) {
r_list_foreach (lib->plugins, iter, p) {
const char *pFileName = r_str_rstr (p->file, R_SYS_DIR);
if (pFileName && !strcmp (fileName, pFileName)) {
return true;
}
}
}
return false;
}

R_API int r_lib_open(RLib *lib, const char *file) {
/* ignored by filename */
if (!__lib_dl_check_filename (file)) {
eprintf ("Invalid library extension: %s\n", file);
return -1;
}

if (__already_loaded (lib, file)) {
eprintf("Not loading library because it has already been loaded from somewhere else: '%s'\n", file);
return -1;
}

void *handler = r_lib_dl_open (file);
if (!handler) {
IFDBG eprintf ("Cannot open library: '%s'\n", file);
Expand All @@ -263,21 +283,6 @@ R_API int r_lib_open(RLib *lib, const char *file) {
return r_lib_open_ptr (lib, file, handler, stru);
}

static bool __alreadyLoaded(RLib *lib, const char *file) {
const char *fileName = r_str_rstr (file, R_SYS_DIR);
RLibPlugin *p;
RListIter *iter;
if (fileName) {
r_list_foreach (lib->plugins, iter, p) {
const char *pFileName = r_str_rstr (p->file, R_SYS_DIR);
if (pFileName && !strcmp (fileName, pFileName)) {
return true;
}
}
}
return false;
}

R_API int r_lib_open_ptr(RLib *lib, const char *file, void *handler, RLibStruct *stru) {
r_return_val_if_fail (lib && file && stru, -1);
if (stru->version) {
Expand All @@ -287,9 +292,6 @@ R_API int r_lib_open_ptr(RLib *lib, const char *file, void *handler, RLibStruct
return -1;
}
}
if (__alreadyLoaded (lib, file)) {
return -1;
}
RLibPlugin *p = R_NEW0 (RLibPlugin);
p->type = stru->type;
p->data = stru->data;
Expand Down

0 comments on commit 0b9edb4

Please sign in to comment.