pki: Make sure no command registers too many options
authorTobias Brunner <tobias@strongswan.org>
Wed, 11 Dec 2013 16:38:18 +0000 (17:38 +0100)
committerTobias Brunner <tobias@strongswan.org>
Thu, 23 Jan 2014 09:12:24 +0000 (10:12 +0100)
src/pki/command.c
src/pki/command.h

index 415e78b..7ccbd96 100644 (file)
@@ -153,17 +153,24 @@ void command_register(command_t command)
        {
                for (i = 0; i < countof(cmds[registered].options) - 1; i++)
                {
-                       if (cmds[registered].options[i].name)
+                       if (!cmds[registered].options[i].name)
                        {
-                               continue;
+                               break;
                        }
+               }
+               if (i > countof(cmds[registered].options) - 3)
+               {
+                       fprintf(stderr, "command '%s' registered too many options, please "
+                                       "increase MAX_OPTIONS\n", command.cmd);
+               }
+               else
+               {
                        cmds[registered].options[i++] = (command_option_t) {
                                "debug",        'v', 1, "set debug level, default: 1"
                        };
                        cmds[registered].options[i++] = (command_option_t) {
                                "options",      '+', 1, "read command line options from file"
                        };
-                       break;
                }
        }
        registered++;
index 3e66a1a..737f465 100644 (file)
@@ -27,7 +27,7 @@
 #define MAX_COMMANDS 11
 
 /**
- * Maximum number of options in a command (+1)
+ * Maximum number of options in a command (+3)
  */
 #define MAX_OPTIONS 32