cryptsetup: fail with error if extraneous arguments are specified

So far the program would silently ignore those… I think it's better to fail.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2023-09-23 11:59:55 +02:00
parent 166015faf5
commit 5bae80bd44

View file

@ -2157,6 +2157,8 @@ static int run(int argc, char *argv[]) {
if (argc - optind < 3)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "attach requires at least two arguments.");
if (argc - optind >= 6)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "attach does not accept more than four arguments.");
const char *volume = ASSERT_PTR(argv[optind + 1]),
*source = ASSERT_PTR(argv[optind + 2]),
@ -2356,6 +2358,9 @@ static int run(int argc, char *argv[]) {
} else if (streq(verb, "detach")) {
const char *volume = ASSERT_PTR(argv[optind + 1]);
if (argc - optind >= 3)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "attach does not accept more than one argument.");
if (!filename_is_valid(volume))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Volume name '%s' is not valid.", volume);