components/openssl/openssl-1.0.1/patches/36_evp_leak.patch
branchs11u2-sru
changeset 3217 6c32d6df504a
child 2156 47340bc31385
equal deleted inserted replaced
3210:cb18d9a0f746 3217:6c32d6df504a
       
     1 Patch developed in-house.  Solaris-specific; not suitable for upstream.
       
     2 
       
     3 --- openssl-1.0.1f/crypto/evp/evp_enc.c.orig	Mon Feb 11 07:26:04 2013
       
     4 +++ openssl-1.0.1f/crypto/evp/evp_enc.c	Mon Feb  3 16:40:48 2014
       
     5 @@ -393,10 +393,14 @@
       
     6  		{
       
     7  		ret = M_do_cipher(ctx, out, NULL, 0);
       
     8  		if (ret < 0)
       
     9 -			return 0;
       
    10 +			{
       
    11 +			ret = 0;
       
    12 +			goto cleanup;
       
    13 +			}
       
    14  		else 
       
    15  			*outl = ret;
       
    16 -		return 1;
       
    17 +		ret = 1;
       
    18 +		goto cleanup;
       
    19  		}
       
    20  
       
    21  	b=ctx->cipher->block_size;
       
    22 @@ -404,7 +408,8 @@
       
    23  	if (b == 1)
       
    24  		{
       
    25  		*outl=0;
       
    26 -		return 1;
       
    27 +		ret = 1;
       
    28 +		goto cleanup;
       
    29  		}
       
    30  	bl=ctx->buf_len;
       
    31  	if (ctx->flags & EVP_CIPH_NO_PADDING)
       
    32 @@ -412,10 +417,12 @@
       
    33  		if(bl)
       
    34  			{
       
    35  			EVPerr(EVP_F_EVP_ENCRYPTFINAL_EX,EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH);
       
    36 -			return 0;
       
    37 +			ret = 0;
       
    38 +			goto cleanup;
       
    39  			}
       
    40  		*outl = 0;
       
    41 -		return 1;
       
    42 +		ret = 1;
       
    43 +		goto cleanup;
       
    44  		}
       
    45  
       
    46  	n=b-bl;
       
    47 @@ -427,6 +434,12 @@
       
    48  	if(ret)
       
    49  		*outl=b;
       
    50  
       
    51 +cleanup:
       
    52 +	if (ctx->cipher->cleanup)
       
    53 +		{
       
    54 +		ctx->cipher->cleanup(ctx);
       
    55 +		}
       
    56 +
       
    57  	return ret;
       
    58  	}
       
    59  
       
    60 @@ -500,7 +513,7 @@
       
    61  
       
    62  int EVP_DecryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
       
    63  	{
       
    64 -	int i,n;
       
    65 +	int i,n,ret = 1;
       
    66  	unsigned int b;
       
    67  	*outl=0;
       
    68  
       
    69 @@ -508,10 +521,14 @@
       
    70  		{
       
    71  		i = M_do_cipher(ctx, out, NULL, 0);
       
    72  		if (i < 0)
       
    73 -			return 0;
       
    74 +			{
       
    75 +			ret = 0;
       
    76 +			goto cleanup;
       
    77 +			}
       
    78  		else
       
    79  			*outl = i;
       
    80 -		return 1;
       
    81 +		ret = 1;
       
    82 +		goto cleanup;
       
    83  		}
       
    84  
       
    85  	b=ctx->cipher->block_size;
       
    86 @@ -520,10 +537,12 @@
       
    87  		if(ctx->buf_len)
       
    88  			{
       
    89  			EVPerr(EVP_F_EVP_DECRYPTFINAL_EX,EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH);
       
    90 -			return 0;
       
    91 +			ret = 0;
       
    92 +			goto cleanup;
       
    93  			}
       
    94  		*outl = 0;
       
    95 -		return 1;
       
    96 +		ret = 1;
       
    97 +		goto cleanup;
       
    98  		}
       
    99  	if (b > 1)
       
   100  		{
       
   101 @@ -530,7 +549,8 @@
       
   102  		if (ctx->buf_len || !ctx->final_used)
       
   103  			{
       
   104  			EVPerr(EVP_F_EVP_DECRYPTFINAL_EX,EVP_R_WRONG_FINAL_BLOCK_LENGTH);
       
   105 -			return(0);
       
   106 +			ret = 0;
       
   107 +			goto cleanup;
       
   108  			}
       
   109  		OPENSSL_assert(b <= sizeof ctx->final);
       
   110  		n=ctx->final[b-1];
       
   111 @@ -537,7 +557,8 @@
       
   112  		if (n == 0 || n > (int)b)
       
   113  			{
       
   114  			EVPerr(EVP_F_EVP_DECRYPTFINAL_EX,EVP_R_BAD_DECRYPT);
       
   115 -			return(0);
       
   116 +			ret = 0;
       
   117 +			goto cleanup;
       
   118  			}
       
   119  		for (i=0; i<n; i++)
       
   120  			{
       
   121 @@ -544,7 +565,8 @@
       
   122  			if (ctx->final[--b] != n)
       
   123  				{
       
   124  				EVPerr(EVP_F_EVP_DECRYPTFINAL_EX,EVP_R_BAD_DECRYPT);
       
   125 -				return(0);
       
   126 +				ret = 0;
       
   127 +				goto cleanup;
       
   128  				}
       
   129  			}
       
   130  		n=ctx->cipher->block_size-n;
       
   131 @@ -554,7 +576,14 @@
       
   132  		}
       
   133  	else
       
   134  		*outl=0;
       
   135 -	return(1);
       
   136 +
       
   137 +cleanup:
       
   138 +	if (ctx->cipher->cleanup)
       
   139 +		{
       
   140 +		ctx->cipher->cleanup(ctx);
       
   141 +		}
       
   142 +
       
   143 +	return ret;
       
   144  	}
       
   145  
       
   146  void EVP_CIPHER_CTX_free(EVP_CIPHER_CTX *ctx)