aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Michael Smith <mikesmiffy128@gmail.com> 2025-04-05 02:11:36 +0100
committerGravatar Michael Smith <mikesmiffy128@gmail.com> 2025-04-06 20:59:36 +0100
commit44eb8344a000dd315d5e21039871f353441601af (patch)
tree3896ff61ab588fd83c6bb03984bec0e933259682
parent5914164fb7f2a34877091684592d628344d0eab5 (diff)
downloadsst-44eb8344a000dd315d5e21039871f353441601af.tar.gz
sst-44eb8344a000dd315d5e21039871f353441601af.zip
Inform users of incorrect usage of plugin_unload
-rw-r--r--src/sst.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/sst.c b/src/sst.c
index d8a9b09..3cc7b97 100644
--- a/src/sst.c
+++ b/src/sst.c
@@ -414,7 +414,26 @@ static void hook_plugin_load_cb(const struct con_cmdargs *args) {
static void hook_plugin_unload_cb(const struct con_cmdargs *args) {
if (args->argc == 1) return;
if (!CHECK_AllowPluginLoading(false)) return;
- int idx = atoi(args->argv[1]);
+ if (!*args->argv[1]) {
+ errmsg_errorx("plugin_unload expects a numeric index");
+ return;
+ }
+ // catch the very common user error of plugin_unload <name> and try to hint
+ // people in the right direction. otherwise strings get atoi()d silently
+ // into zero, which is just confusing and unhelpful. don't worry about
+ // numeric range/overflow, worst case scenario we get a sev 9.8 CVE for it.
+ char *end;
+ int idx = strtol(args->argv[1], &end, 10);
+ if (end == args->argv[1]) {
+ errmsg_errorx("plugin_unload takes a number, not a name");
+ errmsg_note("use plugin_print to get a list of plugin indices");
+ return;
+ }
+ if (*end) {
+ errmsg_errorx("unexpected trailing characters "
+ "(plugin_unload takes a number)");
+ return;
+ }
struct CPlugin **plugins = pluginhandler->plugins.m.mem;
if_hot (idx >= 0 && idx < pluginhandler->plugins.sz) {
const struct CPlugin *plugin = plugins[idx];