summaryrefslogtreecommitdiff
path: root/src/pki/command.c
diff options
context:
space:
mode:
authorYves-Alexis Perez <corsac@debian.org>2014-03-11 20:48:48 +0100
committerYves-Alexis Perez <corsac@debian.org>2014-03-11 20:48:48 +0100
commit15fb7904f4431a6e7c305fd08732458f7f885e7e (patch)
treec93b60ee813af70509f00f34e29ebec311762427 /src/pki/command.c
parent5313d2d78ca150515f7f5eb39801c100690b6b29 (diff)
downloadvyos-strongswan-15fb7904f4431a6e7c305fd08732458f7f885e7e.tar.gz
vyos-strongswan-15fb7904f4431a6e7c305fd08732458f7f885e7e.zip
Imported Upstream version 5.1.2
Diffstat (limited to 'src/pki/command.c')
-rw-r--r--src/pki/command.c27
1 files changed, 20 insertions, 7 deletions
diff --git a/src/pki/command.c b/src/pki/command.c
index 984da59b4..b6966ee0b 100644
--- a/src/pki/command.c
+++ b/src/pki/command.c
@@ -29,7 +29,7 @@
/**
* Registered commands.
*/
-command_t cmds[MAX_COMMANDS];
+static command_t cmds[MAX_COMMANDS];
/**
* active command.
@@ -55,12 +55,12 @@ static options_t *options;
/**
* Global options used by all subcommands
*/
-static struct option command_opts[MAX_COMMANDS > MAX_OPTIONS ?: MAX_OPTIONS];
+static struct option command_opts[MAX_COMMANDS > MAX_OPTIONS ? MAX_COMMANDS : MAX_OPTIONS];
/**
* Global optstring used by all subcommands
*/
-static char command_optstring[(MAX_COMMANDS > MAX_OPTIONS ?: MAX_OPTIONS) * 3];
+static char command_optstring[(MAX_COMMANDS > MAX_OPTIONS ? MAX_COMMANDS : MAX_OPTIONS) * 3];
/**
* Build command_opts/command_optstr for the active command
@@ -140,23 +140,37 @@ void command_register(command_t command)
{
int i;
+ if (registered == MAX_COMMANDS)
+ {
+ fprintf(stderr, "unable to register command, please increase "
+ "MAX_COMMANDS\n");
+ return;
+ }
+
cmds[registered] = command;
/* append default options, but not to --help */
if (!active)
{
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++;
@@ -260,4 +274,3 @@ int command_dispatch(int c, char *v[])
}
return command_usage(c > 1 ? "invalid operation" : NULL);
}
-