]> git.ipfire.org Git - thirdparty/nettle.git/commitdiff
des: assign value after sanity check to avoid undefined behavior
authorNikos Mavrogiannopoulos <nmav@redhat.com>
Thu, 10 Mar 2016 16:53:01 +0000 (17:53 +0100)
committerNiels Möller <nisse@lysator.liu.se>
Tue, 15 Mar 2016 18:19:46 +0000 (19:19 +0100)
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

diff --git a/des.c b/des.c
index f880f8f868638e8d651cf706ceac7ffd00cd8345..ebde9351a91b13adbe7fac10ca27715845a0f5fd 100644 (file)
--- 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;