summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/ipset.c96
1 files changed, 46 insertions, 50 deletions
diff --git a/src/ipset.c b/src/ipset.c
index 2cfcfac..7dbb303 100644
--- a/src/ipset.c
+++ b/src/ipset.c
@@ -470,61 +470,57 @@ parse_commandline(int argc, char *argv[])
/* Second: parse command */
for (command = ipset_commands;
- command->cmd && cmd == IPSET_CMD_NONE;
+ argc > 1 && command->cmd && cmd == IPSET_CMD_NONE;
command++) {
- for (i = 1; i < argc; ) {
- if (!ipset_match_cmd(argv[1], command->name)) {
- i++;
- continue;
- }
- if (restore_line != 0
- && (command->cmd == IPSET_CMD_RESTORE
- || command->cmd == IPSET_CMD_VERSION
- || command->cmd == IPSET_CMD_HELP))
+ if (!ipset_match_cmd(argv[1], command->name))
+ continue;
+
+ if (restore_line != 0
+ && (command->cmd == IPSET_CMD_RESTORE
+ || command->cmd == IPSET_CMD_VERSION
+ || command->cmd == IPSET_CMD_HELP))
+ return exit_error(PARAMETER_PROBLEM,
+ "Command `%s' is invalid "
+ "in restore mode.",
+ command->name[0]);
+ if (interactive && command->cmd == IPSET_CMD_RESTORE) {
+ printf("Restore command ignored "
+ "in interactive mode\n");
+ return 0;
+ }
+
+ /* Shift off matched command arg */
+ ipset_shift_argv(&argc, argv, 1);
+ cmd = command->cmd;
+ switch (command->has_arg) {
+ case IPSET_MANDATORY_ARG:
+ case IPSET_MANDATORY_ARG2:
+ if (argc < 2)
return exit_error(PARAMETER_PROBLEM,
- "Command `%s' is invalid "
- "in restore mode.",
+ "Missing mandatory argument "
+ "to command %s",
command->name[0]);
- if (interactive
- && command->cmd == IPSET_CMD_RESTORE) {
- printf("Restore command ignored "
- "in interactive mode\n");
- return 0;
- }
-
- /* Shift off matched command arg */
- ipset_shift_argv(&argc, argv, i);
- cmd = command->cmd;
- switch (command->has_arg) {
- case IPSET_MANDATORY_ARG:
- case IPSET_MANDATORY_ARG2:
- if (i + 1 > argc)
- return exit_error(PARAMETER_PROBLEM,
- "Missing mandatory argument "
- "to command %s",
- command->name[0]);
- /* Fall through */
- case IPSET_OPTIONAL_ARG:
- arg0 = argv[i];
- if (i + 1 <= argc)
- /* Shift off first arg */
- ipset_shift_argv(&argc, argv, i);
- break;
- default:
- break;
- }
- if (command->has_arg == IPSET_MANDATORY_ARG2) {
- if (i + 1 > argc)
- return exit_error(PARAMETER_PROBLEM,
- "Missing second mandatory "
- "argument to command %s",
- command->name[0]);
- arg1 = argv[i];
- /* Shift off second arg */
- ipset_shift_argv(&argc, argv, i);
- }
+ /* Fall through */
+ case IPSET_OPTIONAL_ARG:
+ arg0 = argv[1];
+ if (argc >= 2)
+ /* Shift off first arg */
+ ipset_shift_argv(&argc, argv, 1);
+ break;
+ default:
break;
}
+ if (command->has_arg == IPSET_MANDATORY_ARG2) {
+ if (argc < 2)
+ return exit_error(PARAMETER_PROBLEM,
+ "Missing second mandatory "
+ "argument to command %s",
+ command->name[0]);
+ arg1 = argv[1];
+ /* Shift off second arg */
+ ipset_shift_argv(&argc, argv, 1);
+ }
+ break;
}
/* Third: catch interactive mode, handle help, version */