Fix null deref in rlang ##lang

This commit is contained in:
pancake 2022-12-08 18:57:12 +01:00
parent 77efdaca74
commit 71c7a53661
2 changed files with 15 additions and 2 deletions

View File

@ -390,13 +390,21 @@ static int cmd_hash_bang(RCore *core, const char *input) {
if (ac > 1) {
if (!strcmp (av[1], "-e")) {
char *run_str = strstr (input + 2, "-e") + 2;
r_lang_run_string (core->lang, run_str);
if (run_str) {
r_lang_run_file (core->lang, run_str);
} else {
R_LOG_ERROR ("Invalid file name");
}
} else {
if (r_lang_set_argv (core->lang, ac - 1, &av[1])) {
r_lang_run_file (core->lang, av[1]);
} else {
char *run_str = strstr (input + 2, av[1]);
r_lang_run_file (core->lang, run_str);
if (run_str) {
r_lang_run_file (core->lang, run_str);
} else {
R_LOG_ERROR ("Invalid file name");
}
}
}
} else {

View File

@ -272,12 +272,14 @@ R_API bool r_lang_use_plugin(RLang *lang, RLangPlugin *h) {
}
R_API bool r_lang_use(RLang *lang, const char *name) {
r_return_val_if_fail (lang && name, false);
RLangPlugin *h = r_lang_get_by_name (lang, name);
return h? r_lang_use_plugin (lang, h): false;
}
// TODO: store in r_lang and use it from the plugin?
R_API bool r_lang_set_argv(RLang *lang, int argc, char **argv) {
r_return_val_if_fail (lang && argc >= 0, false);
RLangPlugin *p = R_UNWRAP3 (lang, session, plugin);
if (p && p->set_argv) {
return p->set_argv (lang->session, argc, argv);
@ -286,6 +288,7 @@ R_API bool r_lang_set_argv(RLang *lang, int argc, char **argv) {
}
R_API bool r_lang_run(RLang *lang, const char *code, int len) {
r_return_val_if_fail (lang && code, false);
RLangPlugin *p = R_UNWRAP3 (lang, session, plugin);
if (p && p->run) {
return p->run (lang->session, code, len);
@ -294,10 +297,12 @@ R_API bool r_lang_run(RLang *lang, const char *code, int len) {
}
R_API bool r_lang_run_string(RLang *lang, const char *code) {
r_return_val_if_fail (lang && code, false);
return r_lang_run (lang, code, strlen (code));
}
R_API bool r_lang_run_file(RLang *lang, const char *file) {
r_return_val_if_fail (lang && file, false);
bool ret = false;
RLangPlugin *p = R_UNWRAP3 (lang, session, plugin);
if (p) {