Fix problems found by Coverity scan.

This commit is contained in:
Milan Broz
2018-07-19 13:53:35 +02:00
parent 1112da76f1
commit 561d9ac2bc
2 changed files with 9 additions and 14 deletions

View File

@@ -2110,22 +2110,17 @@ static int action_token(void)
return r; return r;
} }
switch (action) { if (action == ADD)
case ADD: /* adds only luks2-keyring type */ r = _token_add(cd); /* adds only luks2-keyring type */
r = _token_add(cd); else if (action == REMOVE)
break;
case REMOVE:
r = _token_remove(cd); r = _token_remove(cd);
break; else if (action == IMPORT)
case IMPORT:
r = _token_import(cd); r = _token_import(cd);
break; else if (action == EXPORT)
case EXPORT:
r = _token_export(cd); r = _token_export(cd);
break; else {
default:
log_dbg("Internal token action error."); log_dbg("Internal token action error.");
r = EINVAL; r = -EINVAL;
} }
crypt_free(cd); crypt_free(cd);

View File

@@ -640,7 +640,7 @@ int tools_read_json_file(struct crypt_device *cd, const char *file, char **json,
out: out:
if (block && !quit) if (block && !quit)
set_int_block(1); set_int_block(1);
if (fd != STDIN_FILENO) if (fd >= 0 && fd != STDIN_FILENO)
close(fd); close(fd);
if (r && buf) { if (r && buf) {
memset(buf, 0, LUKS2_MAX_MDA_SIZE); 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: out:
if (block && !quit) if (block && !quit)
set_int_block(1); set_int_block(1);
if (fd != STDOUT_FILENO) if (fd >=0 && fd != STDOUT_FILENO)
close(fd); close(fd);
return r; return r;
} }