Merge branch 'command-max-lines'
authorTobias Brunner <tobias@strongswan.org>
Wed, 16 Dec 2015 11:28:22 +0000 (12:28 +0100)
committerTobias Brunner <tobias@strongswan.org>
Wed, 16 Dec 2015 11:28:22 +0000 (12:28 +0100)
Make sure commands registered in pki and swanctl don't exceed the
maximum number of lines available for their usage summary.

Closes strongswan/strongswan#22.

src/pki/command.c
src/pki/command.h
src/swanctl/command.c
src/swanctl/commands/list_certs.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)
                        {
index e55c579..449252e 100644 (file)
@@ -34,7 +34,7 @@
 /**
  * Maximum number of usage summary lines (+1)
  */
-#define MAX_LINES 10
+#define MAX_LINES 11
 
 typedef struct command_t command_t;
 typedef struct command_option_t command_option_t;
index 26c4134..fd9bc00 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)
                        {
index b2ff3b5..2c314d8 100644 (file)
@@ -214,10 +214,9 @@ static void __attribute__ ((constructor))reg()
 {
        command_register((command_t) {
                list_certs, 'x', "list-certs", "list stored certificates",
-               {"[--subject <dn/san>] "
-                "[--type x509|x509_ac|x509_crl|ocsp_response|pubkey]\n         "
-                "[--flag none|ca|aa|ocsp|any] "
-                "[--pem] [--raw|--pretty|--short|--utc]"},
+               {"[--subject <dn/san>] [--pem]",
+                "[--type x509|x509_ac|x509_crl|ocsp_response|pubkey]",
+                "[--flag none|ca|aa|ocsp|any] [--raw|--pretty|--short|--utc]"},
                {
                        {"help",                'h', 0, "show usage information"},
                        {"subject",             's', 1, "filter by certificate subject"},