From 80bca4180a3e4695eb7fd177d9e2711d3ccdac6e Mon Sep 17 00:00:00 2001 From: Michael Ortmann <41313082+michaelortmann@users.noreply.github.com> Date: Wed, 18 Dec 2024 01:32:26 +0100 Subject: [PATCH 1/2] Fix .tcl server add/remove arg parsing --- src/mod/server.mod/tclserv.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/mod/server.mod/tclserv.c b/src/mod/server.mod/tclserv.c index f54796b77..efff0bd22 100644 --- a/src/mod/server.mod/tclserv.c +++ b/src/mod/server.mod/tclserv.c @@ -582,6 +582,10 @@ static int tcl_server STDVAR { BADARGS(2, 5, " subcommand ?host ?port? ?password?"); if (!strcmp(argv[1], "add")) { + if (argc < 3) { + Tcl_SetResult(irp, "Subcommand add needs at least a server host", TCL_STATIC); + return TCL_ERROR; + } ret = add_server(argv[2], argc >= 4 && argv[3] ? argv[3] : "", argc >= 5 && argv[4] ? argv[4] : ""); if (!ret) { server = Tcl_NewListObj(0, NULL); @@ -599,6 +603,10 @@ static int tcl_server STDVAR { Tcl_SetObjResult(irp, server); } } else if (!strcmp(argv[1], "remove")) { + if (argc < 3) { + Tcl_SetResult(irp, "Subcommand remove needs at least a server host", TCL_STATIC); + return TCL_ERROR; + } ret = del_server(argv[2], argc >= 4 && argv[3] ? argv[3] : ""); } else if (!strcmp(argv[1], "list")) { Tcl_Obj *servers = Tcl_NewListObj(0, NULL); From 78cb2605b4aa61855348a54b306442725af5cff8 Mon Sep 17 00:00:00 2001 From: Michael Ortmann <41313082+michaelortmann@users.noreply.github.com> Date: Wed, 18 Dec 2024 04:11:12 +0100 Subject: [PATCH 2/2] Enhance error message --- src/mod/server.mod/tclserv.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mod/server.mod/tclserv.c b/src/mod/server.mod/tclserv.c index efff0bd22..e92d70726 100644 --- a/src/mod/server.mod/tclserv.c +++ b/src/mod/server.mod/tclserv.c @@ -583,7 +583,7 @@ static int tcl_server STDVAR { BADARGS(2, 5, " subcommand ?host ?port? ?password?"); if (!strcmp(argv[1], "add")) { if (argc < 3) { - Tcl_SetResult(irp, "Subcommand add needs at least a server host", TCL_STATIC); + Tcl_SetResult(irp, "wrong # args: should be \"server add host ?port? ?password?\"", TCL_STATIC); return TCL_ERROR; } ret = add_server(argv[2], argc >= 4 && argv[3] ? argv[3] : "", argc >= 5 && argv[4] ? argv[4] : ""); @@ -604,7 +604,7 @@ static int tcl_server STDVAR { } } else if (!strcmp(argv[1], "remove")) { if (argc < 3) { - Tcl_SetResult(irp, "Subcommand remove needs at least a server host", TCL_STATIC); + Tcl_SetResult(irp, "wrong # args: should be \"server remove host ?port? ?password?\"", TCL_STATIC); return TCL_ERROR; } ret = del_server(argv[2], argc >= 4 && argv[3] ? argv[3] : "");