]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
swanctl: Never print more than MAX_LINES of usage summary
authorTobias Brunner <tobias@strongswan.org>
Wed, 16 Dec 2015 10:56:44 +0000 (11:56 +0100)
committerTobias Brunner <tobias@strongswan.org>
Wed, 16 Dec 2015 11:09:20 +0000 (12:09 +0100)
Print a warning if a registered command exceeds that limit.

src/swanctl/command.c

index 26c41346c013b346ac5b932317f504a5bfecec22..fd9bc00831d00aa7d9f6b54ef6cceeaa5d3d24e5 100644 (file)
@@ -176,6 +176,15 @@ void command_register(command_t command)
                                "uri",          'u', 1, "service URI to connect to"
                        };
                }
+               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++;
 }
@@ -217,7 +226,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)
                        {