From de80709985a272f0a41872dd243d8102c75b4f7f Mon Sep 17 00:00:00 2001 From: MrQuantum1915 Date: Thu, 9 Jul 2026 19:55:59 +0530 Subject: [PATCH] lbrz/core/cmd: fix config print for plugins (#6567) --- librz/core/cmd/cmd_eval.c | 75 ++++++++++++++++++++++++++------------- test/db/cmd/cmd_eval | 44 ++++++++++++++++++----- 2 files changed, 85 insertions(+), 34 deletions(-) diff --git a/librz/core/cmd/cmd_eval.c b/librz/core/cmd/cmd_eval.c index d1823686b9..a2adb4e11f 100644 --- a/librz/core/cmd/cmd_eval.c +++ b/librz/core/cmd/cmd_eval.c @@ -444,8 +444,11 @@ static void print_all_plugin_configs(const RzCore *core) { rz_cmd_state_output_fini(&state); } -static RZ_BORROW RzConfig *eval_get_config_obj_by_key(const RzCore *core, const char *config_str) { +static RZ_BORROW RzConfig *eval_get_config_obj_by_key(const RzCore *core, const char *config_str, bool *invalid_plugin) { rz_return_val_if_fail(core && config_str, NULL); + if (invalid_plugin) { + *invalid_plugin = false; + } RzConfig *cfg = NULL; if (!rz_str_startswith(config_str, "plugins")) { return core->config; @@ -459,6 +462,9 @@ static RZ_BORROW RzConfig *eval_get_config_obj_by_key(const RzCore *core, const const char *second_dot = strchr(first_dot + 1, '.'); bool cfg_found = false; if (!second_dot) { + if (RZ_STR_ISEMPTY(first_dot + 1)) { + return NULL; + } cfg = ht_sp_find(core->plugin_configs, first_dot + 1, &cfg_found); } else { char *config_name = rz_sub_str_ptr(config_str, first_dot + 1, second_dot - 1); @@ -467,11 +473,29 @@ static RZ_BORROW RzConfig *eval_get_config_obj_by_key(const RzCore *core, const } if (!cfg_found) { RZ_LOG_DEBUG("Did not find plugin config with name '%s'\n", config_str); + if (invalid_plugin) { + *invalid_plugin = true; + } return NULL; } return cfg; } +static RZ_BORROW RzConfig *eval_get_config_obj_by_key_or_error(RzCore *core, const char *config_str, RzCmdStatus *status) { + bool invalid_plugin = false; + RzConfig *cfg = eval_get_config_obj_by_key(core, config_str, &invalid_plugin); + if (!cfg) { + if (invalid_plugin) { + RZ_LOG_ERROR("core: Invalid config key '%s'\n", config_str); + *status = RZ_CMD_STATUS_ERROR; + } else { + print_all_plugin_configs(core); + *status = RZ_CMD_STATUS_OK; + } + } + return cfg; +} + RZ_IPI RzCmdStatus rz_eval_getset_handler(RzCore *core, int argc, const char **argv) { int i; for (i = 1; i < argc; i++) { @@ -490,10 +514,11 @@ RZ_IPI RzCmdStatus rz_eval_getset_handler(RzCore *core, int argc, const char **a continue; } - RzConfig *cfg = NULL; - if (!(cfg = eval_get_config_obj_by_key(core, key))) { - print_all_plugin_configs(core); - return RZ_CMD_STATUS_OK; + RzCmdStatus status; + RzConfig *cfg = eval_get_config_obj_by_key_or_error(core, key, &status); + if (!cfg) { + rz_list_free(l); + return status; } if (llen == 1 && rz_str_endswith(key, ".")) { // no value was set, only key with ".". List possible sub-keys. @@ -523,10 +548,10 @@ RZ_IPI RzCmdStatus rz_eval_getset_handler(RzCore *core, int argc, const char **a RZ_IPI RzCmdStatus rz_eval_list_handler(RzCore *core, int argc, const char **argv, RzCmdStateOutput *state) { const char *arg = argc > 1 ? argv[1] : ""; - RzConfig *cfg = NULL; - if (!(cfg = eval_get_config_obj_by_key(core, arg))) { - print_all_plugin_configs(core); - return RZ_CMD_STATUS_OK; + RzCmdStatus status; + RzConfig *cfg = eval_get_config_obj_by_key_or_error(core, arg, &status); + if (!cfg) { + return status; } rz_core_config_print_all(cfg, arg, state); return RZ_CMD_STATUS_OK; @@ -538,10 +563,10 @@ RZ_IPI RzCmdStatus rz_eval_reset_handler(RzCore *core, int argc, const char **ar } RZ_IPI RzCmdStatus rz_eval_bool_invert_handler(RzCore *core, int argc, const char **argv) { - RzConfig *cfg = NULL; - if (!(cfg = eval_get_config_obj_by_key(core, argv[1]))) { - print_all_plugin_configs(core); - return RZ_CMD_STATUS_OK; + RzCmdStatus status; + RzConfig *cfg = eval_get_config_obj_by_key_or_error(core, argv[1], &status); + if (!cfg) { + return status; } if (!rz_config_toggle(cfg, argv[1])) { RZ_LOG_ERROR("core: Cannot toggle config key '%s'\n", argv[1]); @@ -551,10 +576,10 @@ RZ_IPI RzCmdStatus rz_eval_bool_invert_handler(RzCore *core, int argc, const cha } RZ_IPI RzCmdStatus rz_eval_editor_handler(RzCore *core, int argc, const char **argv) { - RzConfig *cfg = NULL; - if (!(cfg = eval_get_config_obj_by_key(core, argv[1]))) { - print_all_plugin_configs(core); - return RZ_CMD_STATUS_OK; + RzCmdStatus status; + RzConfig *cfg = eval_get_config_obj_by_key_or_error(core, argv[1], &status); + if (!cfg) { + return status; } char *val = rz_config_get_as_string(cfg, argv[1]); if (!val) { @@ -572,10 +597,10 @@ RZ_IPI RzCmdStatus rz_eval_editor_handler(RzCore *core, int argc, const char **a } RZ_IPI RzCmdStatus rz_eval_readonly_handler(RzCore *core, int argc, const char **argv) { - RzConfig *cfg = NULL; - if (!(cfg = eval_get_config_obj_by_key(core, argv[1]))) { - print_all_plugin_configs(core); - return RZ_CMD_STATUS_OK; + RzCmdStatus status; + RzConfig *cfg = eval_get_config_obj_by_key_or_error(core, argv[1], &status); + if (!cfg) { + return status; } if (!rz_config_set_readonly(cfg, argv[1], true)) { @@ -601,10 +626,10 @@ RZ_IPI RzCmdStatus rz_eval_spaces_handler(RzCore *core, int argc, const char **a } RZ_IPI RzCmdStatus rz_eval_type_handler(RzCore *core, int argc, const char **argv) { - RzConfig *cfg = NULL; - if (!(cfg = eval_get_config_obj_by_key(core, argv[1]))) { - print_all_plugin_configs(core); - return RZ_CMD_STATUS_OK; + RzCmdStatus status; + RzConfig *cfg = eval_get_config_obj_by_key_or_error(core, argv[1], &status); + if (!cfg) { + return status; } RzConfigNode *node = rz_config_node_get(cfg, argv[1]); if (!node) { diff --git a/test/db/cmd/cmd_eval b/test/db/cmd/cmd_eval index 4dbee7829c..0208ffb83c 100644 --- a/test/db/cmd/cmd_eval +++ b/test/db/cmd/cmd_eval @@ -193,15 +193,15 @@ zoom.to=0 EOF RUN -NAME=List and set plugin configurations +NAME=List and set hexagon plugin configurations FILE== CMDS=<