pki: Never print more than MAX_LINES of usage summary
authorTobias Brunner <tobias@strongswan.org>
Wed, 16 Dec 2015 10:53:01 +0000 (11:53 +0100)
committerTobias Brunner <tobias@strongswan.org>
Wed, 16 Dec 2015 11:07:13 +0000 (12:07 +0100)
Print a warning if a registered command exceeds that limit.

src/pki/command.c

index 13e8140..ce704db 100644 (file)
@@ -172,6 +172,15 @@ void command_register(command_t command)
                                "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++;
 }
@@ -208,7 +217,7 @@ int command_usage(char *error)
        }
        else
        {
-               for (i = 0; cmds[active].line[i]; i++)
+               for (i = 0; i < MAX_LINES && cmds[active].line[i]; i++)
                {
                        if (i == 0)
                        {