]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
crypto-selftests: fix decryption check condition in test_cipher_aead
authorDaiki Ueno <ueno@gnu.org>
Thu, 30 Jun 2022 12:13:53 +0000 (21:13 +0900)
committerDaiki Ueno <ueno@gnu.org>
Wed, 20 Jul 2022 05:55:35 +0000 (14:55 +0900)
Spotted by gcc-analyzer 12.

Signed-off-by: Daiki Ueno <ueno@gnu.org>
lib/crypto-selftests.c

index 57b50ac514a9c7ce8e899fe989735cfcfb8d8d3c..e51e0826f71aa61e9d34d4637673a94a52cac27e 100644 (file)
@@ -2064,7 +2064,9 @@ static int test_cipher_aead(gnutls_cipher_algorithm_t cipher,
                                    gnutls_assert_val
                                    (GNUTLS_E_SELF_TEST_ERROR);
 
-                       if (s2 != vectors[i].plaintext_size && memcmp(tmp, vectors[i].plaintext, vectors[i].plaintext_size) != 0) {
+                       if (s2 != vectors[i].plaintext_size ||
+                           (vectors[i].plaintext_size > 0 &&
+                            memcmp(tmp2, vectors[i].plaintext, vectors[i].plaintext_size) != 0)) {
                                _gnutls_debug_log("%s test vector %d failed (decryption)!\n",
                                        gnutls_cipher_get_name(cipher), i);
                                return gnutls_assert_val(GNUTLS_E_SELF_TEST_ERROR);