diff --git a/lib/bitlk/bitlk.c b/lib/bitlk/bitlk.c index f242cf10..071290ac 100644 --- a/lib/bitlk/bitlk.c +++ b/lib/bitlk/bitlk.c @@ -329,7 +329,7 @@ static int parse_vmk_entry(struct crypt_device *cd, uint8_t *data, int start, in string = malloc((key_entry_size - BITLK_ENTRY_HEADER_LEN) * 2 + 1); if (!string) return -ENOMEM; - r = crypt_utf16_to_utf8(&string, (const char16_t *) (data + start + BITLK_ENTRY_HEADER_LEN), + r = crypt_utf16_to_utf8(&string, CONST_CAST(char16_t *)(data + start + BITLK_ENTRY_HEADER_LEN), key_entry_size - BITLK_ENTRY_HEADER_LEN); if (r < 0 || !string) { free(string); @@ -680,7 +680,7 @@ int BITLK_read_sb(struct crypt_device *cd, struct bitlk_metadata *params) description = malloc((entry_size - BITLK_ENTRY_HEADER_LEN - BITLK_ENTRY_HEADER_LEN) * 2 + 1); if (!description) return -ENOMEM; - r = crypt_utf16_to_utf8(&description, (const char16_t *) (fve_entries + start + BITLK_ENTRY_HEADER_LEN), + r = crypt_utf16_to_utf8(&description, CONST_CAST(char16_t *)(fve_entries + start + BITLK_ENTRY_HEADER_LEN), entry_size - BITLK_ENTRY_HEADER_LEN); if (r < 0 || !description) { free(description); diff --git a/lib/crypto_backend/crypto_storage.c b/lib/crypto_backend/crypto_storage.c index 962ec2b7..1c15ba89 100644 --- a/lib/crypto_backend/crypto_storage.c +++ b/lib/crypto_backend/crypto_storage.c @@ -151,7 +151,8 @@ static int crypt_sector_iv_init(struct crypt_sector_iv *ctx, static int crypt_sector_iv_generate(struct crypt_sector_iv *ctx, uint64_t sector) { - uint64_t val; + uint64_t val, *u64_iv; + uint32_t *u32_iv; switch (ctx->type) { case IV_NONE: @@ -161,19 +162,24 @@ static int crypt_sector_iv_generate(struct crypt_sector_iv *ctx, uint64_t sector break; case IV_PLAIN: memset(ctx->iv, 0, ctx->iv_size); - *(uint32_t *)ctx->iv = cpu_to_le32(sector & 0xffffffff); + u32_iv = (void *)ctx->iv; + *u32_iv = cpu_to_le32(sector & 0xffffffff); break; case IV_PLAIN64: memset(ctx->iv, 0, ctx->iv_size); - *(uint64_t *)ctx->iv = cpu_to_le64(sector); + u64_iv = (void *)ctx->iv; + *u64_iv = cpu_to_le64(sector); break; case IV_PLAIN64BE: memset(ctx->iv, 0, ctx->iv_size); - *(uint64_t *)&ctx->iv[ctx->iv_size - sizeof(uint64_t)] = cpu_to_be64(sector); + /* iv_size is at least of size u64; usually it is 16 bytes */ + u64_iv = (void *)&ctx->iv[ctx->iv_size - sizeof(uint64_t)]; + *u64_iv = cpu_to_be64(sector); break; case IV_ESSIV: memset(ctx->iv, 0, ctx->iv_size); - *(uint64_t *)ctx->iv = cpu_to_le64(sector); + u64_iv = (void *)ctx->iv; + *u64_iv = cpu_to_le64(sector); return crypt_cipher_encrypt(ctx->cipher, ctx->iv, ctx->iv, ctx->iv_size, NULL, 0); break; @@ -184,7 +190,8 @@ static int crypt_sector_iv_generate(struct crypt_sector_iv *ctx, uint64_t sector break; case IV_EBOIV: memset(ctx->iv, 0, ctx->iv_size); - *(uint64_t *)ctx->iv = cpu_to_le64(sector << ctx->shift); + u64_iv = (void *)ctx->iv; + *u64_iv = cpu_to_le64(sector << ctx->shift); return crypt_cipher_encrypt(ctx->cipher, ctx->iv, ctx->iv, ctx->iv_size, NULL, 0); break; diff --git a/lib/libcryptsetup_macros.h b/lib/libcryptsetup_macros.h index 5fd402c0..3c925ea4 100644 --- a/lib/libcryptsetup_macros.h +++ b/lib/libcryptsetup_macros.h @@ -25,6 +25,9 @@ /* to silent gcc -Wcast-qual for const cast */ #define CONST_CAST(x) (x)(uintptr_t) +/* to silent clang -Wcast-align when working with byte arrays */ +#define VOIDP_CAST(x) (x)(void*) + #define UNUSED(x) (void)(x) #ifndef ARRAY_SIZE diff --git a/lib/libdevmapper.c b/lib/libdevmapper.c index 9bc3d221..ff2aa573 100644 --- a/lib/libdevmapper.c +++ b/lib/libdevmapper.c @@ -332,7 +332,7 @@ static int _dm_check_versions(struct crypt_device *cd, dm_target_type target_typ (unsigned)target->version[1], (unsigned)target->version[2]); } - target = (struct dm_versions *)((char *) target + target->next); + target = VOIDP_CAST(struct dm_versions *)((char *) target + target->next); } while (last_target != target); r = 1; diff --git a/lib/tcrypt/tcrypt.c b/lib/tcrypt/tcrypt.c index 4be73f2f..7aaead04 100644 --- a/lib/tcrypt/tcrypt.c +++ b/lib/tcrypt/tcrypt.c @@ -264,8 +264,8 @@ static int TCRYPT_hdr_from_disk(struct crypt_device *cd, */ static void TCRYPT_swab_le(char *buf) { - uint32_t *l = (uint32_t*)&buf[0]; - uint32_t *r = (uint32_t*)&buf[4]; + uint32_t *l = VOIDP_CAST(uint32_t*)&buf[0]; + uint32_t *r = VOIDP_CAST(uint32_t*)&buf[4]; *l = swab32(*l); *r = swab32(*r); } diff --git a/lib/utils_safe_memory.c b/lib/utils_safe_memory.c index 61370068..8e4bffc7 100644 --- a/lib/utils_safe_memory.c +++ b/lib/utils_safe_memory.c @@ -67,12 +67,13 @@ void crypt_safe_free(void *data) { struct safe_allocation *alloc; volatile size_t *s; + void *p; if (!data) return; - alloc = (struct safe_allocation *) - ((char *)data - offsetof(struct safe_allocation, data)); + p = (char *)data - offsetof(struct safe_allocation, data); + alloc = (struct safe_allocation *)p; crypt_safe_memzero(data, alloc->size); @@ -85,13 +86,14 @@ void *crypt_safe_realloc(void *data, size_t size) { struct safe_allocation *alloc; void *new_data; + void *p; new_data = crypt_safe_alloc(size); if (new_data && data) { - alloc = (struct safe_allocation *) - ((char *)data - offsetof(struct safe_allocation, data)); + p = (char *)data - offsetof(struct safe_allocation, data); + alloc = (struct safe_allocation *)p; if (size > alloc->size) size = alloc->size;