On 30/10/26 16:04, Daniel P. Berrangé wrote:
The glib backend for the hmac/hash code must have an explicit
initializer for every element, as the default static initializer
of zero maps to G_CHECKSUM_MD5 and will lead to incorrect
behaviour. This could potentially be a security through use of
the wrong hashing algorithm.

Fixes: https://gitlab.com/qemu-project/qemu/-/work_items/4786
Signed-off-by: Daniel P. Berrangé <[email protected]>
---
  crypto/hash-glib.c | 1 +
  crypto/hmac-glib.c | 1 +
  2 files changed, 2 insertions(+)

diff --git a/crypto/hash-glib.c b/crypto/hash-glib.c
index 809cef98aee..39040f1856e 100644
--- a/crypto/hash-glib.c
+++ b/crypto/hash-glib.c
@@ -33,6 +33,7 @@ static int qcrypto_hash_alg_map[QCRYPTO_HASH_ALGO__MAX] = {
      [QCRYPTO_HASH_ALGO_SHA384] = G_CHECKSUM_SHA384,
      [QCRYPTO_HASH_ALGO_SHA512] = G_CHECKSUM_SHA512,
      [QCRYPTO_HASH_ALGO_RIPEMD160] = -1,
+    [QCRYPTO_HASH_ALGO_SM3] = -1,
  };

Should we initialize the array with range designator to prevent that?

  [0 ... QCRYPTO_HASH_ALGO__MAX - 1] = -1,


Reply via email to