pki: Never print more than MAX_LINES of usage summary

Print a warning if a registered command exceeds that limit.
This commit is contained in:
Tobias Brunner
2015-12-16 12:07:13 +01:00
parent bf5754adcd
commit 8ea64a78d6
+10 -1
View File
@@ -172,6 +172,15 @@ void command_register(command_t command)
"options", '+', 1, "read command line options from file" "options", '+', 1, "read command line options from file"
}; };
} }
for (i = 0; cmds[registered].line[i]; i++)
{
if (i == MAX_LINES - 1)
{
fprintf(stderr, "command '%s' specifies too many usage summary "
"lines, please increase MAX_LINES\n", command.cmd);
break;
}
}
} }
registered++; registered++;
} }
@@ -208,7 +217,7 @@ int command_usage(char *error)
} }
else else
{ {
for (i = 0; cmds[active].line[i]; i++) for (i = 0; i < MAX_LINES && cmds[active].line[i]; i++)
{ {
if (i == 0) if (i == 0)
{ {