diff --git a/tools/command.c b/tools/command.c index 8198c5f3a..20b1811f8 100644 --- a/tools/command.c +++ b/tools/command.c @@ -941,12 +941,28 @@ static void _add_opt_arg(struct command *cmd, char *str, } skip: - if (required > 0) + if (required > 0) { + if (cmd->ro_count >= CMD_RO_ARGS) { + log_error("Too many args, increase CMD_RO_ARGS."); + cmd->cmd_flags |= CMD_FLAG_PARSE_ERROR; + return; + } cmd->required_opt_args[cmd->ro_count++].opt = opt; - else if (!required) + } else if (!required) { + if (cmd->oo_count >= CMD_OO_ARGS) { + log_error("Too many args, increase CMD_OO_ARGS."); + cmd->cmd_flags |= CMD_FLAG_PARSE_ERROR; + return; + } cmd->optional_opt_args[cmd->oo_count++].opt = opt; - else if (required < 0) + } else if (required < 0) { + if (cmd->io_count >= CMD_IO_ARGS) { + log_error("Too many args, increase CMD_IO_ARGS."); + cmd->cmd_flags |= CMD_FLAG_PARSE_ERROR; + return; + } cmd->ignore_opt_args[cmd->io_count++].opt = opt; + } *takes_arg = opt_names[opt].val_enum ? 1 : 0; } diff --git a/tools/command.h b/tools/command.h index 72391e45c..3497b1fe4 100644 --- a/tools/command.h +++ b/tools/command.h @@ -152,12 +152,12 @@ struct cmd_rule { * of which one is required after which the rest are * optional. */ -#define CMD_RO_ARGS 64 /* required opt args */ -#define CMD_OO_ARGS 100 /* optional opt args */ +#define CMD_RO_ARGS 32 /* required opt args */ +#define CMD_OO_ARGS 64 /* optional opt args */ #define CMD_RP_ARGS 8 /* required positional args */ #define CMD_OP_ARGS 8 /* optional positional args */ #define CMD_IO_ARGS 8 /* ignore opt args */ -#define CMD_MAX_RULES 32 /* max number of rules per command def */ +#define CMD_MAX_RULES 16 /* max number of rules per command def */ /* * one or more from required_opt_args is required,