Fix some warnings found during static analysis.

This commit is contained in:
Milan Broz
2018-01-20 14:13:17 +01:00
parent 08e7c143b3
commit 1ca439f4e0
11 changed files with 21 additions and 22 deletions

View File

@@ -22,7 +22,7 @@
#ifndef _CRYPTSETUP_LUKS2_ONDISK_H
#define _CRYPTSETUP_LUKS2_ONDISK_H
#include <stdint.h>
#include "libcryptsetup.h"
#define LUKS2_MAGIC_1ST "LUKS\xba\xbe"
#define LUKS2_MAGIC_2ND "SKUL\xba\xbe"

View File

@@ -186,7 +186,7 @@ int LUKS2_generate_hdr(
else {
//FIXME
//offset = size_round_up(areas[7].offset + areas[7].length, alignPayload * SECTOR_SIZE);
offset = size_round_up(LUKS2_HDR_DEFAULT_LEN, alignPayload * sector_size);
offset = size_round_up(LUKS2_HDR_DEFAULT_LEN, (size_t)alignPayload * sector_size);
offset += alignOffset;
}

View File

@@ -107,7 +107,7 @@ json_object *LUKS2_get_keyslot_jobj(struct luks2_hdr *hdr, int keyslot)
json_object *jobj1, *jobj2;
char keyslot_name[16];
if (!hdr)
if (!hdr || keyslot < 0)
return NULL;
if (snprintf(keyslot_name, sizeof(keyslot_name), "%u", keyslot) < 1)
@@ -125,7 +125,7 @@ json_object *LUKS2_get_token_jobj(struct luks2_hdr *hdr, int token)
json_object *jobj1, *jobj2;
char token_name[16];
if (!hdr)
if (!hdr || token < 0)
return NULL;
if (snprintf(token_name, sizeof(token_name), "%u", token) < 1)
@@ -143,7 +143,7 @@ json_object *LUKS2_get_digest_jobj(struct luks2_hdr *hdr, int digest)
json_object *jobj1, *jobj2;
char digest_name[16];
if (!hdr)
if (!hdr || digest < 0)
return NULL;
if (snprintf(digest_name, sizeof(digest_name), "%u", digest) < 1)
@@ -161,7 +161,7 @@ json_object *LUKS2_get_segment_jobj(struct luks2_hdr *hdr, int segment)
json_object *jobj1, *jobj2;
char segment_name[16];
if (!hdr)
if (!hdr || segment < 0)
return NULL;
if (snprintf(segment_name, sizeof(segment_name), "%u", segment) < 1)
@@ -193,7 +193,7 @@ static json_bool json_str_to_uint64(json_object *jobj, uint64_t *value)
errno = 0;
tmp = strtoull(json_object_get_string(jobj), &endptr, 10);
if (*endptr || errno || tmp > UINT64_MAX) {
if (*endptr || errno) {
log_dbg("Failed to parse uint64_t type from string %s.",
json_object_get_string(jobj));
*value = 0;

View File

@@ -306,7 +306,7 @@ int LUKS2_keyslot_open(struct crypt_device *cd,
password, password_len, segment, vk);
if (r_prio >= 0)
r = r_prio;
else if (r_prio < 0 && (r_prio != -EPERM) && (r_prio != -ENOENT))
else if (r_prio != -EPERM && r_prio != -ENOENT)
r = r_prio;
else
r = LUKS2_keyslot_open_priority(cd, hdr, CRYPT_SLOT_PRIORITY_NORMAL,