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 @@ -379,11 +379,13 @@ |
|
6 |
|
7 if (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) { |
|
8 ret = M_do_cipher(ctx, out, NULL, 0); |
|
9 - if (ret < 0) |
|
10 - return 0; |
|
11 - else |
|
12 + if (ret < 0) { |
|
13 + ret = 0; |
|
14 + goto cleanup; |
|
15 + } else |
|
16 *outl = ret; |
|
17 - return 1; |
|
18 + ret = 1; |
|
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 } |
|
46 |
|
47 n = b - bl; |
|
48 @@ -411,6 +416,11 @@ |
|
49 if (ret) |
|
50 *outl = b; |
|
51 |
|
52 +cleanup: |
|
53 + if (ctx->cipher->cleanup) { |
|
54 + ctx->cipher->cleanup(ctx); |
|
55 + } |
|
56 + |
|
57 return ret; |
|
58 } |
|
59 |
|
60 @@ -478,6 +488,7 @@ |
|
61 int EVP_DecryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl) |
|
62 { |
|
63 int i, n; |
|
64 + int err = 1; |
|
65 unsigned int b; |
|
66 *outl = 0; |
|
67 |
|
68 @@ -483,11 +494,13 @@ |
|
69 |
|
70 if (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) { |
|
71 i = M_do_cipher(ctx, out, NULL, 0); |
|
72 - if (i < 0) |
|
73 - return 0; |
|
74 - else |
|
75 + if (i < 0) { |
|
76 + err = 0; |
|
77 + goto cleanup; |
|
78 + } else |
|
79 *outl = i; |
|
80 - return 1; |
|
81 + err = 1; |
|
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); |
|
110 |
|
111 @@ -514,7 +530,8 @@ |
|
112 n = ctx->final[b - 1]; |
|
113 if (n == 0 || n > (int)b) { |
|
114 EVPerr(EVP_F_EVP_DECRYPTFINAL_EX, EVP_R_BAD_DECRYPT); |
|
115 - return (0); |
|
116 + err = 0; |
|
117 + goto cleanup; |
|
118 } |
|
119 for (i = 0; i < n; i++) { |
|
120 if (ctx->final[--b] != n) { |
|
121 @@ -519,7 +536,8 @@ |
|
122 for (i = 0; i < n; i++) { |
|
123 if (ctx->final[--b] != n) { |
|
124 EVPerr(EVP_F_EVP_DECRYPTFINAL_EX, EVP_R_BAD_DECRYPT); |
|
125 - return (0); |
|
126 + err = 0; |
|
127 + goto cleanup; |
|
128 } |
|
129 } |
|
130 n = ctx->cipher->block_size - n; |
|
131 @@ -528,7 +546,12 @@ |
|
132 *outl = n; |
|
133 } else |
|
134 *outl = 0; |
|
135 - return (1); |
|
136 + err = 1; |
|
137 +cleanup: |
|
138 + if (ctx->cipher->cleanup) { |
|
139 + ctx->cipher->cleanup(ctx); |
|
140 + } |
|
141 + return err; |
|
142 } |
|
143 |
|
144 void EVP_CIPHER_CTX_free(EVP_CIPHER_CTX *ctx) |
|