Invalid arguments to add_enckey will leak the "arg" allocation,
so fix that.
Fixes: ba71de04 ("xfs_io/encrypt: add 'add_enckey' command")
Fixes-coverity-id:
1454644
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Bill O'Donnell <billodo@redhat.com>
[sandeen: incorporate improvements from Eric Biggers]
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
int c;
struct fscrypt_add_key_arg *arg;
ssize_t raw_size;
+ int retval = 0;
arg = calloc(1, sizeof(*arg) + FSCRYPT_MAX_KEY_SIZE + 1);
if (!arg) {
goto out;
break;
default:
- return command_usage(&add_enckey_cmd);
+ retval = command_usage(&add_enckey_cmd);
+ goto out;
}
}
argc -= optind;
argv += optind;
- if (argc != 0)
- return command_usage(&add_enckey_cmd);
+ if (argc != 0) {
+ retval = command_usage(&add_enckey_cmd);
+ goto out;
+ }
raw_size = read_until_limit_or_eof(STDIN_FILENO, arg->raw,
FSCRYPT_MAX_KEY_SIZE + 1);
out:
memset(arg->raw, 0, FSCRYPT_MAX_KEY_SIZE + 1);
free(arg);
- return 0;
+ return retval;
}
static int