[v1,5/5] ima-evm-utils: Fix clang warning about possible unaligned pointer for hdr->keyid
diff mbox series

Message ID 20190707234837.4866-6-vt@altlinux.org
State New
Headers show
Series
  • ima-evm-utils: Assorted fixes and improvements
Related show

Commit Message

Vitaly Chikunov July 7, 2019, 11:48 p.m. UTC
Struct signature_v2_hdr is packed so clang complains that taking address
of packed member may result in an unaligned pointer value:

libimaevm.c:481:21: warning: taking address of packed member 'keyid' of class or structure 'signature_v2_hdr' may result in an unaligned pointer value
      [-Waddress-of-packed-member]
                                __be32_to_cpup(&hdr->keyid));
                                                ^~~~~~~~~~

libimaevm.c:905:17: warning: taking address of packed member 'keyid' of class or structure 'signature_v2_hdr' may result in an unaligned pointer value
      [-Waddress-of-packed-member]
        calc_keyid_v2(&hdr->keyid, name, pkey);
                       ^~~~~~~~~~

Signed-off-by: Vitaly Chikunov <vt@altlinux.org>
---
 src/libimaevm.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

Patch
diff mbox series

diff --git a/src/libimaevm.c b/src/libimaevm.c
index b556276..f8ab812 100644
--- a/src/libimaevm.c
+++ b/src/libimaevm.c
@@ -475,10 +475,12 @@  int verify_hash_v2(const char *file, const unsigned char *hash, int size,
 	}
 
 	if (public_keys) {
-		pkey = find_keyid(hdr->keyid);
+		uint32_t keyid = hdr->keyid;
+
+		pkey = find_keyid(keyid);
 		if (!pkey) {
 			log_err("%s: unknown keyid: %x\n", file,
-				__be32_to_cpup(&hdr->keyid));
+				__be32_to_cpup(&keyid));
 			return -1;
 		}
 	} else {
@@ -869,6 +871,7 @@  int sign_hash_v2(const char *algo, const unsigned char *hash, int size, const ch
 	const EVP_MD *md;
 	size_t sigsize;
 	const char *st;
+	uint32_t keyid;
 
 	if (!hash) {
 		log_err("sign_hash_v2: hash is null\n");
@@ -902,7 +905,8 @@  int sign_hash_v2(const char *algo, const unsigned char *hash, int size, const ch
 
 	hdr->hash_algo = get_hash_algo(algo);
 
-	calc_keyid_v2(&hdr->keyid, name, pkey);
+	calc_keyid_v2(&keyid, name, pkey);
+	hdr->keyid = keyid;
 
 	st = "EVP_PKEY_CTX_new";
 	if (!(ctx = EVP_PKEY_CTX_new(pkey, NULL)))