From 45a19a4bc6c72c07dcd4cd7e84b2c2bbdb3f60dd Mon Sep 17 00:00:00 2001 From: Nikos Mavrogiannopoulos Date: Thu, 10 Mar 2016 17:53:01 +0100 Subject: [PATCH] des: assign value after sanity check to avoid undefined behavior This corrects issues of the following type caught with -fsanitize=undefined des.c:176:42: runtime error: index 42 out of bounds for type 'int8_t [26][4]' --- des.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/des.c b/des.c index f880f8f8..ebde9351 100644 --- a/des.c +++ b/des.c @@ -173,10 +173,13 @@ des_weak_p(const uint8_t *key) int8_t k1 = key[1] >> 1; unsigned hash = asso_values[k1 + 1] + asso_values[k0]; - const int8_t *candidate = weak_key_hash[hash]; + const int8_t *candidate; if (hash > 25) return 0; + + candidate = weak_key_hash[hash]; + if (k0 != candidate[0] || k1 != candidate[1]) return 0; -- 2.47.2