components/openssl/openssl-1.0.1/patches/36_evp_leak.patch
branchs11u2-sru8-backport
changeset 4020 8e3f49e23eaa
parent 3624 70b1e516a3e9
equal deleted inserted replaced
3862:0e46f6a07b7f 4020:8e3f49e23eaa
     1 Patch developed in-house.  Solaris-specific; not suitable for upstream.
     1 Patch developed in-house.  Solaris-specific; not suitable for upstream.
     2 
     2 
     3 --- openssl-1.0.1f/crypto/evp/evp_enc.c.orig	Mon Feb 11 07:26:04 2013
     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
     4 +++ openssl-1.0.1f/crypto/evp/evp_enc.c    Mon Feb  3 16:40:48 2014
     5 @@ -394,10 +394,14 @@
     5 @@ -379,11 +379,13 @@
     6  		{
     6 
     7  		ret = M_do_cipher(ctx, out, NULL, 0);
     7      if (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) {
     8  		if (ret < 0)
     8          ret = M_do_cipher(ctx, out, NULL, 0);
     9 -			return 0;
     9 -        if (ret < 0)
    10 +			{
    10 -            return 0;
    11 +			ret = 0;
    11 -        else
    12 +			goto cleanup;
    12 +        if (ret < 0) {
    13 +			}
    13 +            ret = 0;
    14  		else 
    14 +            goto cleanup;
    15  			*outl = ret;
    15 +        } else
    16 -		return 1;
    16              *outl = ret;
    17 +		ret = 1;
    17 -        return 1;
    18 +		goto cleanup;
    18 +        ret = 1;
    19  		}
    19 +        goto cleanup;
       
    20      }
       
    21 
       
    22      b = ctx->cipher->block_size;
       
    23 @@ -390,7 +392,8 @@
       
    24      OPENSSL_assert(b <= sizeof ctx->buf);
       
    25      if (b == 1) {
       
    26          *outl = 0;
       
    27 -        return 1;
       
    28 +        ret = 1;
       
    29 +        goto cleanup;
       
    30      }
       
    31      bl = ctx->buf_len;
       
    32      if (ctx->flags & EVP_CIPH_NO_PADDING) {
       
    33 @@ -397,10 +400,12 @@
       
    34          if (bl) {
       
    35              EVPerr(EVP_F_EVP_ENCRYPTFINAL_EX,
       
    36                     EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH);
       
    37 -            return 0;
       
    38 +            ret = 0;
       
    39 +            goto cleanup;
       
    40          }
       
    41          *outl = 0;
       
    42 -        return 1;
       
    43 +        ret = 1;
       
    44 +        goto cleanup;
       
    45      }
    20  
    46  
    21  	b=ctx->cipher->block_size;
    47      n = b - bl;
    22 @@ -405,7 +409,8 @@
    48 @@ -411,6 +416,11 @@
    23  	if (b == 1)
    49      if (ret)
    24  		{
    50          *outl = b;
    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 @@ -413,10 +418,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 @@ -428,6 +435,12 @@
       
    48  	if(ret)
       
    49  		*outl=b;
       
    50  
    51  
    51 +cleanup:
    52 +cleanup:
    52 +	if (ctx->cipher->cleanup)
    53 +    if (ctx->cipher->cleanup) {
    53 +		{
    54 +        ctx->cipher->cleanup(ctx);
    54 +		ctx->cipher->cleanup(ctx);
    55 +    }
    55 +		}
       
    56 +
    56 +
    57  	return ret;
    57      return ret;
    58  	}
    58  }
    59  
    59  
    60 @@ -501,6 +501,7 @@
    60 @@ -478,6 +488,7 @@
    61  int EVP_DecryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
    61  int EVP_DecryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
    62  	{
    62  {
    63  	int i,n;
    63      int i, n;
    64 +	int err = 1;
    64 +    int err = 1;
    65  	unsigned int b;
    65      unsigned int b;
    66  	*outl=0;
    66      *outl = 0;
    67  
    67  
    68 @@ -508,10 +509,14 @@
    68 @@ -483,11 +494,13 @@
    69  		{
    69 
    70  		i = M_do_cipher(ctx, out, NULL, 0);
    70      if (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) {
    71  		if (i < 0)
    71          i = M_do_cipher(ctx, out, NULL, 0);
    72 -			return 0;
    72 -        if (i < 0)
    73 +			{
    73 -            return 0;
    74 +			err = 0;
    74 -        else
    75 +			goto cleanup;
    75 +        if (i < 0) {
    76 +			}
    76 +            err = 0;
    77  		else
    77 +            goto cleanup;
    78  			*outl = i;
    78 +        } else
    79 -		return 1;
    79              *outl = i;
    80 +		err = 1;
    80 -        return 1;
    81 +		goto cleanup;
    81 +        err = 1;
    82  		}
    82 +        goto cleanup;
       
    83      }
       
    84 
       
    85      b = ctx->cipher->block_size;
       
    86 @@ -495,10 +508,12 @@
       
    87          if (ctx->buf_len) {
       
    88              EVPerr(EVP_F_EVP_DECRYPTFINAL_EX,
       
    89                     EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH);
       
    90 -            return 0;
       
    91 +            err = 0;
       
    92 +            goto cleanup;
       
    93          }
       
    94          *outl = 0;
       
    95 -        return 1;
       
    96 +        err = 1;
       
    97 +        goto cleanup;
       
    98      }
       
    99      if (b > 1) {
       
   100          if (ctx->buf_len || !ctx->final_used) {
       
   101 @@ -503,7 +518,8 @@
       
   102      if (b > 1) {
       
   103          if (ctx->buf_len || !ctx->final_used) {
       
   104              EVPerr(EVP_F_EVP_DECRYPTFINAL_EX, EVP_R_WRONG_FINAL_BLOCK_LENGTH);
       
   105 -            return (0);
       
   106 +            err = 0;
       
   107 +            goto cleanup;
       
   108          }
       
   109          OPENSSL_assert(b <= sizeof ctx->final);
    83  
   110  
    84  	b=ctx->cipher->block_size;
   111 @@ -514,7 +530,8 @@
    85 @@ -520,10 +525,12 @@
   112          n = ctx->final[b - 1];
    86  		if(ctx->buf_len)
   113          if (n == 0 || n > (int)b) {
    87  			{
   114              EVPerr(EVP_F_EVP_DECRYPTFINAL_EX, EVP_R_BAD_DECRYPT);
    88  			EVPerr(EVP_F_EVP_DECRYPTFINAL_EX,EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH);
   115 -            return (0);
    89 -			return 0;
   116 +            err = 0;
    90 +			err = 0;
   117 +            goto cleanup;
    91 +			goto cleanup;
   118          }
    92  			}
   119          for (i = 0; i < n; i++) {
    93  		*outl = 0;
   120              if (ctx->final[--b] != n) {
    94 -		return 1;
   121 @@ -519,7 +536,8 @@
    95 +		err = 1;
   122          for (i = 0; i < n; i++) {
    96 +		goto cleanup;
   123              if (ctx->final[--b] != n) {
    97  		}
   124                  EVPerr(EVP_F_EVP_DECRYPTFINAL_EX, EVP_R_BAD_DECRYPT);
    98  	if (b > 1)
   125 -                return (0);
    99  		{
   126 +                err = 0;
   100 @@ -530,7 +537,8 @@
   127 +                goto cleanup;
   101  		if (ctx->buf_len || !ctx->final_used)
   128              }
   102  			{
   129          }
   103  			EVPerr(EVP_F_EVP_DECRYPTFINAL_EX,EVP_R_WRONG_FINAL_BLOCK_LENGTH);
   130          n = ctx->cipher->block_size - n;
   104 -			return(0);
   131 @@ -528,7 +546,12 @@
   105 +			err = 0;
   132          *outl = n;
   106 +			goto cleanup;
   133      } else
   107  			}
   134          *outl = 0;
   108  		OPENSSL_assert(b <= sizeof ctx->final);
   135 -    return (1);
   109  
   136 +    err = 1;
   110 @@ -542,7 +550,8 @@
       
   111  		if (n == 0 || n > (int)b)
       
   112  			{
       
   113  			EVPerr(EVP_F_EVP_DECRYPTFINAL_EX,EVP_R_BAD_DECRYPT);
       
   114 -			return(0);
       
   115 +			err = 0;
       
   116 +			goto cleanup;
       
   117  			}
       
   118  		for (i=0; i<n; i++)
       
   119  			{
       
   120 @@ -549,7 +558,8 @@
       
   121  			if (ctx->final[--b] != n)
       
   122  				{
       
   123  				EVPerr(EVP_F_EVP_DECRYPTFINAL_EX,EVP_R_BAD_DECRYPT);
       
   124 -				return(0);
       
   125 +				err = 0;
       
   126 +				goto cleanup;
       
   127  				}
       
   128  			}
       
   129  		n=ctx->cipher->block_size-n;
       
   130 @@ -559,7 +569,13 @@
       
   131  		}
       
   132  	else
       
   133  		*outl=0;
       
   134 -	return(1);
       
   135 +	err = 1;
       
   136 +cleanup:
   137 +cleanup:
   137 +	if (ctx->cipher->cleanup)
   138 +    if (ctx->cipher->cleanup) {
   138 +		{
   139 +        ctx->cipher->cleanup(ctx);
   139 +		ctx->cipher->cleanup(ctx);
   140 +    }
   140 +		}
   141 +    return err;
   141 +	return err;
   142  }
   142  	}
       
   143  
   143  
   144  void EVP_CIPHER_CTX_free(EVP_CIPHER_CTX *ctx)
   144  void EVP_CIPHER_CTX_free(EVP_CIPHER_CTX *ctx)