dev_crypto_cipher: return immediately if allocating cin/cout failed
[openssl.git] / crypto / evp / openbsd_hw.c
index 3831a5731e9cd5340daccff94d64146403f34af4..0554019489e7c40c24e738a534715d3dcafb1a9f 100644 (file)
@@ -134,6 +134,8 @@ static int dev_crypto_init_key(EVP_CIPHER_CTX *ctx,int cipher,
        return 0;
 
     CDATA(ctx)->key=OPENSSL_malloc(MAX_HW_KEY);
+    if (CDATA(ctx)->key == NULL)
+        return 0;
 
     assert(ctx->cipher->iv_len <= MAX_HW_IV);
 
@@ -191,6 +193,8 @@ static int dev_crypto_cipher(EVP_CIPHER_CTX *ctx,unsigned char *out,
            if(((unsigned long)in&3) || cinl != inl)
                {
                cin=OPENSSL_malloc(cinl);
+               if (cin == NULL)
+                   return 0;
                memcpy(cin,in,inl);
                cryp.src=cin;
                }
@@ -198,6 +202,12 @@ static int dev_crypto_cipher(EVP_CIPHER_CTX *ctx,unsigned char *out,
            if(((unsigned long)out&3) || cinl != inl)
                {
                cout=OPENSSL_malloc(cinl);
+               if (cout == NULL)
+                   {
+                   if (cin != NULL)
+                       OPENSSL_free(cin);
+                   return 0;
+                   }
                cryp.dst=cout;
                }