Commit e734f0a6 authored by Jaroslava Fiedlerova's avatar Jaroslava Fiedlerova

Merge remote-tracking branch 'origin/telnet-longer-command-names' into integration_2026_w11 (!3981)

Bugfix: make longer telnet cmdfunc names

The maximum number of cmdfunc names is 20, which IMO is too low. Worse, if it's
longer, nothing will warn us because C will just fill the array to it's end
(without \0 at the end). To remedy this:

- Allow longer names till 64 bytes (I hit the previous limit of 20)
- Check that the name is within the length limit: if somebody wants a very long
  name, the strnlen() will return the maximum length, hitting that assertion.
- When reading a command during runtime, allow the corresponding maximum length.

On that occasion, also increase total number of permitted cmdfuncs.
parents 592cb8ac d82b5c1e
...@@ -561,7 +561,7 @@ int process_command(char *buf, int iteration) ...@@ -561,7 +561,7 @@ int process_command(char *buf, int iteration)
} }
rt=CMDSTATUS_NOTFOUND; rt=CMDSTATUS_NOTFOUND;
j = sscanf(buf,"%19s %19s %m[^\t\n]",modulename,cmd,&cmdb); j = sscanf(buf,"%19s %63s %m[^\t\n]",modulename,cmd,&cmdb);
if (telnetparams.telnetdbg > 0) if (telnetparams.telnetdbg > 0)
printf("process_command: %i words, module=%s cmd=%s, parameters= %s\n", j, modulename, cmd, (cmdb == NULL) ? "" : cmdb); printf("process_command: %i words, module=%s cmd=%s, parameters= %s\n", j, modulename, cmd, (cmdb == NULL) ? "" : cmdb);
...@@ -947,6 +947,12 @@ int add_telnetcmd(char *modulename, telnetshell_vardef_t *var, telnetshell_cmdde ...@@ -947,6 +947,12 @@ int add_telnetcmd(char *modulename, telnetshell_vardef_t *var, telnetshell_cmdde
telnetparams.CmdParsers[i].cmd = cmd; telnetparams.CmdParsers[i].cmd = cmd;
telnetparams.CmdParsers[i].var = var; telnetparams.CmdParsers[i].var = var;
for (int j = 0; cmd[j].cmdfunc != NULL; j++) { for (int j = 0; cmd[j].cmdfunc != NULL; j++) {
size_t cmdnamelen = strnlen(cmd[j].cmdname, TELNET_CMD_MAXSIZE);
AssertFatal(cmdnamelen < TELNET_CMD_MAXSIZE,
"cmdname %s too long: %ld >= %d",
cmd[j].cmdname,
cmdnamelen,
TELNET_CMD_MAXSIZE);
if (cmd[j].cmdflags & TELNETSRV_CMDFLAG_PUSHINTPOOLQ) { if (cmd[j].cmdflags & TELNETSRV_CMDFLAG_PUSHINTPOOLQ) {
if (afifo == NULL) { if (afifo == NULL) {
afifo = calloc_or_fail(1, sizeof(notifiedFIFO_t)); afifo = calloc_or_fail(1, sizeof(notifiedFIFO_t));
......
...@@ -35,8 +35,8 @@ ...@@ -35,8 +35,8 @@
#define TELNET_MAX_MSGLENGTH 2048 #define TELNET_MAX_MSGLENGTH 2048
#define TELNET_PROMPT_PREFIX "softmodem" #define TELNET_PROMPT_PREFIX "softmodem"
#define TELNET_MAXCMD 20 #define TELNET_MAXCMD 64
#define TELNET_CMD_MAXSIZE 20 #define TELNET_CMD_MAXSIZE 64
#define TELNET_HELPSTR_SIZE 80 #define TELNET_HELPSTR_SIZE 80
/* status return by the command parser after it analysed user input */ /* status return by the command parser after it analysed user input */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment