From 561d9ac2bc050a8ef4c37f1e0b5e2ba534886cf6 Mon Sep 17 00:00:00 2001 From: Milan Broz Date: Thu, 19 Jul 2018 13:53:35 +0200 Subject: [PATCH] Fix problems found by Coverity scan. --- src/cryptsetup.c | 19 +++++++------------ src/utils_tools.c | 4 ++-- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/cryptsetup.c b/src/cryptsetup.c index 2792b37d..0740afc7 100644 --- a/src/cryptsetup.c +++ b/src/cryptsetup.c @@ -2110,22 +2110,17 @@ static int action_token(void) return r; } - switch (action) { - case ADD: /* adds only luks2-keyring type */ - r = _token_add(cd); - break; - case REMOVE: + if (action == ADD) + r = _token_add(cd); /* adds only luks2-keyring type */ + else if (action == REMOVE) r = _token_remove(cd); - break; - case IMPORT: + else if (action == IMPORT) r = _token_import(cd); - break; - case EXPORT: + else if (action == EXPORT) r = _token_export(cd); - break; - default: + else { log_dbg("Internal token action error."); - r = EINVAL; + r = -EINVAL; } crypt_free(cd); diff --git a/src/utils_tools.c b/src/utils_tools.c index a0740f36..6cfd66cc 100644 --- a/src/utils_tools.c +++ b/src/utils_tools.c @@ -640,7 +640,7 @@ int tools_read_json_file(struct crypt_device *cd, const char *file, char **json, out: if (block && !quit) set_int_block(1); - if (fd != STDIN_FILENO) + if (fd >= 0 && fd != STDIN_FILENO) close(fd); if (r && buf) { memset(buf, 0, LUKS2_MAX_MDA_SIZE); @@ -694,7 +694,7 @@ int tools_write_json_file(struct crypt_device *cd, const char *file, const char out: if (block && !quit) set_int_block(1); - if (fd != STDOUT_FILENO) + if (fd >=0 && fd != STDOUT_FILENO) close(fd); return r; }