From e107af6c768a6d45d74e34635c169175b068ab29 Mon Sep 17 00:00:00 2001
From: Nikos Mavrogiannopoulos <nmav@redhat.com>
Date: Thu, 10 Mar 2016 17:53:01 +0100
Subject: [PATCH 2/3] 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 f880f8f..ebde935 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.5.0

