Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move Lib already loaded check before dlopen Call #15075

Merged
merged 1 commit into from
Sep 19, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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