]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
priority: refactor ciphersuite filtering
authorAlexander Sosedkin <asosedkin@redhat.com>
Wed, 20 Oct 2021 12:34:58 +0000 (14:34 +0200)
committerAlexander Sosedkin <asosedkin@redhat.com>
Thu, 21 Oct 2021 08:47:08 +0000 (10:47 +0200)
Signed-off-by: Alexander Sosedkin <asosedkin@redhat.com>
lib/priority.c

index f043e9dd6f23ff8bc7b16a5dc8d505e85dda143f..0530bcb9e53cf3113b6e9c3d13fb982815eeb7f3 100644 (file)
@@ -1682,10 +1682,11 @@ static int set_ciphersuite_list(gnutls_priority_t priority_cache)
                        ce = cipher_suite_get(
                                0, priority_cache->_cipher.priorities[j],
                                priority_cache->_mac.priorities[z]);
+                       if (ce == NULL)
+                               continue;
 
-                       if (ce != NULL && priority_cache->cs.size < MAX_CIPHERSUITE_SIZE) {
+                       if (priority_cache->cs.size < MAX_CIPHERSUITE_SIZE)
                                priority_cache->cs.entry[priority_cache->cs.size++] = ce;
-                       }
                }
        }
 
@@ -1696,18 +1697,20 @@ static int set_ciphersuite_list(gnutls_priority_t priority_cache)
                                        priority_cache->_kx.priorities[i],
                                        priority_cache->_cipher.priorities[j],
                                        priority_cache->_mac.priorities[z]);
+                               if (ce == NULL)
+                                       continue;
 
-                               if (ce != NULL && priority_cache->cs.size < MAX_CIPHERSUITE_SIZE) {
-                                       priority_cache->cs.entry[priority_cache->cs.size++] = ce;
-                                       if (!have_ec && (_gnutls_kx_is_ecc(ce->kx_algorithm) ||
-                                                        _gnutls_kx_is_vko_gost(ce->kx_algorithm))) {
-                                               have_ec = 1;
-                                               add_ec(priority_cache);
-                                       }
-                                       if (!have_dh && _gnutls_kx_is_dhe(ce->kx_algorithm)) {
-                                               have_dh = 1;
-                                               add_dh(priority_cache);
-                                       }
+                               if (priority_cache->cs.size == MAX_CIPHERSUITE_SIZE)
+                                       continue;
+                               priority_cache->cs.entry[priority_cache->cs.size++] = ce;
+                               if (!have_ec && (_gnutls_kx_is_ecc(ce->kx_algorithm) ||
+                                                _gnutls_kx_is_vko_gost(ce->kx_algorithm))) {
+                                       have_ec = 1;
+                                       add_ec(priority_cache);
+                               }
+                               if (!have_dh && _gnutls_kx_is_dhe(ce->kx_algorithm)) {
+                                       have_dh = 1;
+                                       add_dh(priority_cache);
                                }
                        }
                }