Commit d82b5c1e authored by Robert Schmidt's avatar Robert Schmidt

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.
parent 582ce818
......@@ -561,7 +561,7 @@ int process_command(char *buf, int iteration)
}
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)
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
telnetparams.CmdParsers[i].cmd = cmd;
telnetparams.CmdParsers[i].var = var;
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 (afifo == NULL) {
afifo = calloc_or_fail(1, sizeof(notifiedFIFO_t));
......
......@@ -35,8 +35,8 @@
#define TELNET_MAX_MSGLENGTH 2048
#define TELNET_PROMPT_PREFIX "softmodem"
#define TELNET_MAXCMD 20
#define TELNET_CMD_MAXSIZE 20
#define TELNET_MAXCMD 64
#define TELNET_CMD_MAXSIZE 64
#define TELNET_HELPSTR_SIZE 80
/* 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