]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
apps: fix coverity 1358776, 1451513, 1451519, 1451531 & 1473387: unchecked return...
authorPauli <ppzgs1@gmail.com>
Thu, 18 Mar 2021 23:11:02 +0000 (09:11 +1000)
committerPauli <pauli@openssl.org>
Thu, 25 Mar 2021 22:46:01 +0000 (08:46 +1000)
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14615)

apps/speed.c

index 30e703632f1b5c0e49019c1ea92b118b039ed895..0bd566e846644f3d453c41c5667ed20f3aa816f3 100644 (file)
@@ -729,7 +729,11 @@ static EVP_CIPHER_CTX *init_evp_cipher_ctx(const char *ciphername,
         goto end;
     }
 
-    EVP_CIPHER_CTX_set_key_length(ctx, keylen);
+    if (!EVP_CIPHER_CTX_set_key_length(ctx, keylen)) {
+        EVP_CIPHER_CTX_free(ctx);
+        ctx = NULL;
+        goto end;
+    }
 
     if (!EVP_CipherInit_ex(ctx, NULL, NULL, key, iv, 1)) {
         EVP_CIPHER_CTX_free(ctx);
@@ -838,19 +842,19 @@ static int EVP_Update_loop_aead(void *args)
 
     if (decrypt) {
         for (count = 0; COND(c[D_EVP][testnum]); count++) {
-            EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, iv);
-            EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG,
-                                sizeof(faketag), faketag);
-            EVP_DecryptUpdate(ctx, NULL, &outl, aad, sizeof(aad));
-            EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
-            EVP_DecryptFinal_ex(ctx, buf + outl, &outl);
+            (void)EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, iv);
+            (void)EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG,
+                                      sizeof(faketag), faketag);
+            (void)EVP_DecryptUpdate(ctx, NULL, &outl, aad, sizeof(aad));
+            (void)EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
+            (void)EVP_DecryptFinal_ex(ctx, buf + outl, &outl);
         }
     } else {
         for (count = 0; COND(c[D_EVP][testnum]); count++) {
-            EVP_EncryptInit_ex(ctx, NULL, NULL, NULL, iv);
-            EVP_EncryptUpdate(ctx, NULL, &outl, aad, sizeof(aad));
-            EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
-            EVP_EncryptFinal_ex(ctx, buf + outl, &outl);
+            (void)EVP_EncryptInit_ex(ctx, NULL, NULL, NULL, iv);
+            (void)EVP_EncryptUpdate(ctx, NULL, &outl, aad, sizeof(aad));
+            (void)EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
+            (void)EVP_EncryptFinal_ex(ctx, buf + outl, &outl);
         }
     }
     return count;
@@ -3610,20 +3614,27 @@ static void multiblock_speed(const EVP_CIPHER *evp_cipher, int lengths_single,
 
     inp = app_malloc(mblengths[num - 1], "multiblock input buffer");
     out = app_malloc(mblengths[num - 1] + 1024, "multiblock output buffer");
-    ctx = EVP_CIPHER_CTX_new();
-    EVP_EncryptInit_ex(ctx, evp_cipher, NULL, NULL, no_iv);
+    if ((ctx = EVP_CIPHER_CTX_new()) == NULL)
+        app_bail_out("failed to allocate cipher context\n");
+    if (!EVP_EncryptInit_ex(ctx, evp_cipher, NULL, NULL, no_iv))
+        app_bail_out("failed to initialise cipher context\n");
 
     if ((keylen = EVP_CIPHER_CTX_key_length(ctx)) < 0) {
         BIO_printf(bio_err, "Impossible negative key length: %d\n", keylen);
         return;
     }
     key = app_malloc(keylen, "evp_cipher key");
-    EVP_CIPHER_CTX_rand_key(ctx, key);
-    EVP_EncryptInit_ex(ctx, NULL, NULL, key, NULL);
+    if (!EVP_CIPHER_CTX_rand_key(ctx, key))
+        app_bail_out("failed to generate random cipher key\n");
+    if (!EVP_EncryptInit_ex(ctx, NULL, NULL, key, NULL))
+        app_bail_out("failed to set cipher key\n");
     OPENSSL_clear_free(key, keylen);
 
-    EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_MAC_KEY, sizeof(no_key), no_key);
-    alg_name = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
+    if (!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_MAC_KEY,
+                             sizeof(no_key), no_key))
+        app_bail_out("failed to set AEAD key\n");
+    if ((alg_name = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher))) == NULL)
+        app_bail_out("failed to get cipher name\n");
 
     for (j = 0; j < num; j++) {
         print_message(alg_name, 0, mblengths[j], seconds->sym);