1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-03 05:18:29 +03:00

commands: reduce command structure size more

Check for internal limits, if they would ever need to be raised report
error message and fail parsing.
This commit is contained in:
Zdenek Kabelac 2024-03-28 17:04:37 +01:00
parent 8965fd18aa
commit f1e80f3be0
2 changed files with 22 additions and 6 deletions

View File

@ -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;
}

View File

@ -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,