diff options
author | jsing <> | 2014-04-17 16:14:15 +0000 |
---|---|---|
committer | jsing <> | 2014-04-17 16:14:15 +0000 |
commit | 574615861e3df22894a32f87f1f6650a0f1073c8 (patch) | |
tree | be2338f314e3adfbaa6821139dc5a3e45922cb61 /src/lib | |
parent | 18c3f2b77b5cab0b6689479dee685aff2566defe (diff) | |
download | openbsd-574615861e3df22894a32f87f1f6650a0f1073c8.tar.gz openbsd-574615861e3df22894a32f87f1f6650a0f1073c8.tar.bz2 openbsd-574615861e3df22894a32f87f1f6650a0f1073c8.zip |
Initial KNF.
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/libcrypto/asn1/a_bitstr.c | 274 | ||||
-rw-r--r-- | src/lib/libcrypto/asn1/a_bool.c | 86 | ||||
-rw-r--r-- | src/lib/libcrypto/asn1/a_bytes.c | 373 | ||||
-rw-r--r-- | src/lib/libcrypto/asn1/a_d2i_fp.c | 280 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/asn1/a_bitstr.c | 274 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/asn1/a_bool.c | 86 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/asn1/a_bytes.c | 373 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/asn1/a_d2i_fp.c | 280 |
8 files changed, 1010 insertions, 1016 deletions
diff --git a/src/lib/libcrypto/asn1/a_bitstr.c b/src/lib/libcrypto/asn1/a_bitstr.c index e2b65bf2ac..5633cfca1c 100644 --- a/src/lib/libcrypto/asn1/a_bitstr.c +++ b/src/lib/libcrypto/asn1/a_bitstr.c | |||
@@ -5,21 +5,21 @@ | |||
5 | * This package is an SSL implementation written | 5 | * This package is an SSL implementation written |
6 | * by Eric Young (eay@cryptsoft.com). | 6 | * by Eric Young (eay@cryptsoft.com). |
7 | * The implementation was written so as to conform with Netscapes SSL. | 7 | * The implementation was written so as to conform with Netscapes SSL. |
8 | * | 8 | * |
9 | * This library is free for commercial and non-commercial use as long as | 9 | * This library is free for commercial and non-commercial use as long as |
10 | * the following conditions are aheared to. The following conditions | 10 | * the following conditions are aheared to. The following conditions |
11 | * apply to all code found in this distribution, be it the RC4, RSA, | 11 | * apply to all code found in this distribution, be it the RC4, RSA, |
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation |
13 | * included with this distribution is covered by the same copyright terms | 13 | * included with this distribution is covered by the same copyright terms |
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). |
15 | * | 15 | * |
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | 16 | * Copyright remains Eric Young's, and as such any Copyright notices in |
17 | * the code are not to be removed. | 17 | * the code are not to be removed. |
18 | * If this package is used in a product, Eric Young should be given attribution | 18 | * If this package is used in a product, Eric Young should be given attribution |
19 | * as the author of the parts of the library used. | 19 | * as the author of the parts of the library used. |
20 | * This can be in the form of a textual message at program startup or | 20 | * This can be in the form of a textual message at program startup or |
21 | * in documentation (online or textual) provided with the package. | 21 | * in documentation (online or textual) provided with the package. |
22 | * | 22 | * |
23 | * Redistribution and use in source and binary forms, with or without | 23 | * Redistribution and use in source and binary forms, with or without |
24 | * modification, are permitted provided that the following conditions | 24 | * modification, are permitted provided that the following conditions |
25 | * are met: | 25 | * are met: |
@@ -34,10 +34,10 @@ | |||
34 | * Eric Young (eay@cryptsoft.com)" | 34 | * Eric Young (eay@cryptsoft.com)" |
35 | * The word 'cryptographic' can be left out if the rouines from the library | 35 | * The word 'cryptographic' can be left out if the rouines from the library |
36 | * being used are not cryptographic related :-). | 36 | * being used are not cryptographic related :-). |
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | 37 | * 4. If you include any Windows specific code (or a derivative thereof) from |
38 | * the apps directory (application code) you must include an acknowledgement: | 38 | * the apps directory (application code) you must include an acknowledgement: |
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" |
40 | * | 40 | * |
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND |
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
@@ -49,7 +49,7 @@ | |||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
51 | * SUCH DAMAGE. | 51 | * SUCH DAMAGE. |
52 | * | 52 | * |
53 | * The licence and distribution terms for any publically available version or | 53 | * The licence and distribution terms for any publically available version or |
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be |
55 | * copied and put under another distribution licence | 55 | * copied and put under another distribution licence |
@@ -60,82 +60,91 @@ | |||
60 | #include "cryptlib.h" | 60 | #include "cryptlib.h" |
61 | #include <openssl/asn1.h> | 61 | #include <openssl/asn1.h> |
62 | 62 | ||
63 | int ASN1_BIT_STRING_set(ASN1_BIT_STRING *x, unsigned char *d, int len) | 63 | int |
64 | { return M_ASN1_BIT_STRING_set(x, d, len); } | 64 | ASN1_BIT_STRING_set(ASN1_BIT_STRING *x, unsigned char *d, int len) |
65 | { | ||
66 | return M_ASN1_BIT_STRING_set(x, d, len); | ||
67 | } | ||
65 | 68 | ||
66 | int i2c_ASN1_BIT_STRING(ASN1_BIT_STRING *a, unsigned char **pp) | 69 | int |
67 | { | 70 | i2c_ASN1_BIT_STRING(ASN1_BIT_STRING *a, unsigned char **pp) |
68 | int ret,j,bits,len; | 71 | { |
69 | unsigned char *p,*d; | 72 | int ret, j,bits, len; |
73 | unsigned char *p, *d; | ||
70 | 74 | ||
71 | if (a == NULL) return(0); | 75 | if (a == NULL) |
76 | return (0); | ||
72 | 77 | ||
73 | len=a->length; | 78 | len = a->length; |
74 | 79 | ||
75 | if (len > 0) | 80 | if (len > 0) { |
76 | { | 81 | if (a->flags & ASN1_STRING_FLAG_BITS_LEFT) { |
77 | if (a->flags & ASN1_STRING_FLAG_BITS_LEFT) | 82 | bits = (int)a->flags & 0x07; |
78 | { | 83 | } else { |
79 | bits=(int)a->flags&0x07; | 84 | for (; len > 0; len--) { |
80 | } | 85 | if (a->data[len - 1]) |
81 | else | 86 | break; |
82 | { | ||
83 | for ( ; len > 0; len--) | ||
84 | { | ||
85 | if (a->data[len-1]) break; | ||
86 | } | ||
87 | j=a->data[len-1]; | ||
88 | if (j & 0x01) bits=0; | ||
89 | else if (j & 0x02) bits=1; | ||
90 | else if (j & 0x04) bits=2; | ||
91 | else if (j & 0x08) bits=3; | ||
92 | else if (j & 0x10) bits=4; | ||
93 | else if (j & 0x20) bits=5; | ||
94 | else if (j & 0x40) bits=6; | ||
95 | else if (j & 0x80) bits=7; | ||
96 | else bits=0; /* should not happen */ | ||
97 | } | 87 | } |
88 | j = a->data[len - 1]; | ||
89 | if (j & 0x01) | ||
90 | bits = 0; | ||
91 | else if (j & 0x02) | ||
92 | bits = 1; | ||
93 | else if (j & 0x04) | ||
94 | bits = 2; | ||
95 | else if (j & 0x08) | ||
96 | bits = 3; | ||
97 | else if (j & 0x10) | ||
98 | bits = 4; | ||
99 | else if (j & 0x20) | ||
100 | bits = 5; | ||
101 | else if (j & 0x40) | ||
102 | bits = 6; | ||
103 | else if (j & 0x80) | ||
104 | bits = 7; | ||
105 | else | ||
106 | bits = 0; /* should not happen */ | ||
98 | } | 107 | } |
99 | else | 108 | } else |
100 | bits=0; | 109 | bits = 0; |
101 | 110 | ||
102 | ret=1+len; | 111 | ret = 1 + len; |
103 | if (pp == NULL) return(ret); | 112 | if (pp == NULL) |
113 | return (ret); | ||
104 | 114 | ||
105 | p= *pp; | 115 | p= *pp; |
106 | 116 | ||
107 | *(p++)=(unsigned char)bits; | 117 | *(p++) = (unsigned char)bits; |
108 | d=a->data; | 118 | d = a->data; |
109 | memcpy(p,d,len); | 119 | memcpy(p, d, len); |
110 | p+=len; | 120 | p += len; |
111 | if (len > 0) p[-1]&=(0xff<<bits); | 121 | if (len > 0) |
112 | *pp=p; | 122 | p[-1]&=(0xff << bits); |
113 | return(ret); | 123 | *pp = p; |
114 | } | 124 | return (ret); |
125 | } | ||
115 | 126 | ||
116 | ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a, | 127 | ASN1_BIT_STRING * |
117 | const unsigned char **pp, long len) | 128 | c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a, const unsigned char **pp, long len) |
118 | { | 129 | { |
119 | ASN1_BIT_STRING *ret=NULL; | 130 | ASN1_BIT_STRING *ret = NULL; |
120 | const unsigned char *p; | 131 | const unsigned char *p; |
121 | unsigned char *s; | 132 | unsigned char *s; |
122 | int i; | 133 | int i; |
123 | 134 | ||
124 | if (len < 1) | 135 | if (len < 1) { |
125 | { | 136 | i = ASN1_R_STRING_TOO_SHORT; |
126 | i=ASN1_R_STRING_TOO_SHORT; | ||
127 | goto err; | 137 | goto err; |
128 | } | 138 | } |
129 | 139 | ||
130 | if ((a == NULL) || ((*a) == NULL)) | 140 | if ((a == NULL) || ((*a) == NULL)) { |
131 | { | 141 | if ((ret = M_ASN1_BIT_STRING_new()) == NULL) |
132 | if ((ret=M_ASN1_BIT_STRING_new()) == NULL) return(NULL); | 142 | return (NULL); |
133 | } | 143 | } else |
134 | else | 144 | ret = (*a); |
135 | ret=(*a); | ||
136 | 145 | ||
137 | p= *pp; | 146 | p = *pp; |
138 | i= *(p++); | 147 | i = *(p++); |
139 | /* We do this to preserve the settings. If we modify | 148 | /* We do this to preserve the settings. If we modify |
140 | * the settings, via the _set_bit function, we will recalculate | 149 | * the settings, via the _set_bit function, we will recalculate |
141 | * on output */ | 150 | * on output */ |
@@ -143,106 +152,111 @@ ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a, | |||
143 | ret->flags|=(ASN1_STRING_FLAG_BITS_LEFT|(i&0x07)); /* set */ | 152 | ret->flags|=(ASN1_STRING_FLAG_BITS_LEFT|(i&0x07)); /* set */ |
144 | 153 | ||
145 | if (len-- > 1) /* using one because of the bits left byte */ | 154 | if (len-- > 1) /* using one because of the bits left byte */ |
146 | { | 155 | { |
147 | s=(unsigned char *)malloc((int)len); | 156 | s = (unsigned char *)malloc((int)len); |
148 | if (s == NULL) | 157 | if (s == NULL) { |
149 | { | 158 | i = ERR_R_MALLOC_FAILURE; |
150 | i=ERR_R_MALLOC_FAILURE; | ||
151 | goto err; | 159 | goto err; |
152 | } | ||
153 | memcpy(s,p,(int)len); | ||
154 | s[len-1]&=(0xff<<i); | ||
155 | p+=len; | ||
156 | } | 160 | } |
157 | else | 161 | memcpy(s, p, (int)len); |
158 | s=NULL; | 162 | s[len - 1] &= (0xff << i); |
159 | 163 | p += len; | |
160 | ret->length=(int)len; | 164 | } else |
161 | if (ret->data != NULL) free(ret->data); | 165 | s = NULL; |
162 | ret->data=s; | 166 | |
163 | ret->type=V_ASN1_BIT_STRING; | 167 | ret->length = (int)len; |
164 | if (a != NULL) (*a)=ret; | 168 | if (ret->data != NULL) |
165 | *pp=p; | 169 | free(ret->data); |
166 | return(ret); | 170 | ret->data = s; |
171 | ret->type = V_ASN1_BIT_STRING; | ||
172 | if (a != NULL) | ||
173 | (*a) = ret; | ||
174 | *pp = p; | ||
175 | return (ret); | ||
176 | |||
167 | err: | 177 | err: |
168 | ASN1err(ASN1_F_C2I_ASN1_BIT_STRING,i); | 178 | ASN1err(ASN1_F_C2I_ASN1_BIT_STRING, i); |
169 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) | 179 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) |
170 | M_ASN1_BIT_STRING_free(ret); | 180 | M_ASN1_BIT_STRING_free(ret); |
171 | return(NULL); | 181 | return (NULL); |
172 | } | 182 | } |
173 | 183 | ||
174 | /* These next 2 functions from Goetz Babin-Ebell <babinebell@trustcenter.de> | 184 | /* These next 2 functions from Goetz Babin-Ebell <babinebell@trustcenter.de> |
175 | */ | 185 | */ |
176 | int ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value) | 186 | int |
177 | { | 187 | ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value) |
178 | int w,v,iv; | 188 | { |
189 | int w, v, iv; | ||
179 | unsigned char *c; | 190 | unsigned char *c; |
180 | 191 | ||
181 | w=n/8; | 192 | w = n/8; |
182 | v=1<<(7-(n&0x07)); | 193 | v = 1 << (7 - (n & 0x07)); |
183 | iv= ~v; | 194 | iv = ~v; |
184 | if (!value) v=0; | 195 | if (!value) |
196 | v = 0; | ||
185 | 197 | ||
186 | if (a == NULL) | 198 | if (a == NULL) |
187 | return 0; | 199 | return 0; |
188 | 200 | ||
189 | a->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); /* clear, set on write */ | 201 | a->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); /* clear, set on write */ |
190 | 202 | ||
191 | if ((a->length < (w+1)) || (a->data == NULL)) | 203 | if ((a->length < (w + 1)) || (a->data == NULL)) { |
192 | { | 204 | if (!value) |
193 | if (!value) return(1); /* Don't need to set */ | 205 | return(1); /* Don't need to set */ |
194 | if (a->data == NULL) | 206 | if (a->data == NULL) |
195 | c=(unsigned char *)malloc(w+1); | 207 | c = (unsigned char *)malloc(w + 1); |
196 | else | 208 | else |
197 | c=(unsigned char *)OPENSSL_realloc_clean(a->data, | 209 | c = (unsigned char *)OPENSSL_realloc_clean(a->data, |
198 | a->length, | 210 | a->length, w + 1); |
199 | w+1); | 211 | if (c == NULL) { |
200 | if (c == NULL) | 212 | ASN1err(ASN1_F_ASN1_BIT_STRING_SET_BIT, ERR_R_MALLOC_FAILURE); |
201 | { | ||
202 | ASN1err(ASN1_F_ASN1_BIT_STRING_SET_BIT,ERR_R_MALLOC_FAILURE); | ||
203 | return 0; | 213 | return 0; |
204 | } | 214 | } |
205 | if (w+1-a->length > 0) memset(c+a->length, 0, w+1-a->length); | 215 | if (w + 1 - a->length > 0) |
206 | a->data=c; | 216 | memset(c + a->length, 0, w + 1 - a->length); |
207 | a->length=w+1; | 217 | a->data = c; |
218 | a->length = w + 1; | ||
208 | } | 219 | } |
209 | a->data[w]=((a->data[w])&iv)|v; | 220 | a->data[w] = ((a->data[w]) & iv) | v; |
210 | while ((a->length > 0) && (a->data[a->length-1] == 0)) | 221 | while ((a->length > 0) && (a->data[a->length - 1] == 0)) |
211 | a->length--; | 222 | a->length--; |
212 | return(1); | ||
213 | } | ||
214 | 223 | ||
215 | int ASN1_BIT_STRING_get_bit(ASN1_BIT_STRING *a, int n) | 224 | return (1); |
216 | { | 225 | } |
217 | int w,v; | ||
218 | 226 | ||
219 | w=n/8; | 227 | int |
220 | v=1<<(7-(n&0x07)); | 228 | ASN1_BIT_STRING_get_bit(ASN1_BIT_STRING *a, int n) |
221 | if ((a == NULL) || (a->length < (w+1)) || (a->data == NULL)) | 229 | { |
222 | return(0); | 230 | int w, v; |
223 | return((a->data[w]&v) != 0); | 231 | |
224 | } | 232 | w = n / 8; |
233 | v = 1 << (7 - (n & 0x07)); | ||
234 | if ((a == NULL) || (a->length < (w + 1)) || (a->data == NULL)) | ||
235 | return (0); | ||
236 | return ((a->data[w] & v) != 0); | ||
237 | } | ||
225 | 238 | ||
226 | /* | 239 | /* |
227 | * Checks if the given bit string contains only bits specified by | 240 | * Checks if the given bit string contains only bits specified by |
228 | * the flags vector. Returns 0 if there is at least one bit set in 'a' | 241 | * the flags vector. Returns 0 if there is at least one bit set in 'a' |
229 | * which is not specified in 'flags', 1 otherwise. | 242 | * which is not specified in 'flags', 1 otherwise. |
230 | * 'len' is the length of 'flags'. | 243 | * 'len' is the length of 'flags'. |
231 | */ | 244 | */ |
232 | int ASN1_BIT_STRING_check(ASN1_BIT_STRING *a, | 245 | int |
233 | unsigned char *flags, int flags_len) | 246 | ASN1_BIT_STRING_check(ASN1_BIT_STRING *a, unsigned char *flags, int flags_len) |
234 | { | 247 | { |
235 | int i, ok; | 248 | int i, ok; |
249 | |||
236 | /* Check if there is one bit set at all. */ | 250 | /* Check if there is one bit set at all. */ |
237 | if (!a || !a->data) return 1; | 251 | if (!a || !a->data) |
252 | return 1; | ||
238 | 253 | ||
239 | /* Check each byte of the internal representation of the bit string. */ | 254 | /* Check each byte of the internal representation of the bit string. */ |
240 | ok = 1; | 255 | ok = 1; |
241 | for (i = 0; i < a->length && ok; ++i) | 256 | for (i = 0; i < a->length && ok; ++i) { |
242 | { | ||
243 | unsigned char mask = i < flags_len ? ~flags[i] : 0xff; | 257 | unsigned char mask = i < flags_len ? ~flags[i] : 0xff; |
244 | /* We are done if there is an unneeded bit set. */ | 258 | /* We are done if there is an unneeded bit set. */ |
245 | ok = (a->data[i] & mask) == 0; | 259 | ok = (a->data[i] & mask) == 0; |
246 | } | ||
247 | return ok; | ||
248 | } | 260 | } |
261 | return ok; | ||
262 | } | ||
diff --git a/src/lib/libcrypto/asn1/a_bool.c b/src/lib/libcrypto/asn1/a_bool.c index 331acdf053..c8c180d6f7 100644 --- a/src/lib/libcrypto/asn1/a_bool.c +++ b/src/lib/libcrypto/asn1/a_bool.c | |||
@@ -5,21 +5,21 @@ | |||
5 | * This package is an SSL implementation written | 5 | * This package is an SSL implementation written |
6 | * by Eric Young (eay@cryptsoft.com). | 6 | * by Eric Young (eay@cryptsoft.com). |
7 | * The implementation was written so as to conform with Netscapes SSL. | 7 | * The implementation was written so as to conform with Netscapes SSL. |
8 | * | 8 | * |
9 | * This library is free for commercial and non-commercial use as long as | 9 | * This library is free for commercial and non-commercial use as long as |
10 | * the following conditions are aheared to. The following conditions | 10 | * the following conditions are aheared to. The following conditions |
11 | * apply to all code found in this distribution, be it the RC4, RSA, | 11 | * apply to all code found in this distribution, be it the RC4, RSA, |
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation |
13 | * included with this distribution is covered by the same copyright terms | 13 | * included with this distribution is covered by the same copyright terms |
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). |
15 | * | 15 | * |
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | 16 | * Copyright remains Eric Young's, and as such any Copyright notices in |
17 | * the code are not to be removed. | 17 | * the code are not to be removed. |
18 | * If this package is used in a product, Eric Young should be given attribution | 18 | * If this package is used in a product, Eric Young should be given attribution |
19 | * as the author of the parts of the library used. | 19 | * as the author of the parts of the library used. |
20 | * This can be in the form of a textual message at program startup or | 20 | * This can be in the form of a textual message at program startup or |
21 | * in documentation (online or textual) provided with the package. | 21 | * in documentation (online or textual) provided with the package. |
22 | * | 22 | * |
23 | * Redistribution and use in source and binary forms, with or without | 23 | * Redistribution and use in source and binary forms, with or without |
24 | * modification, are permitted provided that the following conditions | 24 | * modification, are permitted provided that the following conditions |
25 | * are met: | 25 | * are met: |
@@ -34,10 +34,10 @@ | |||
34 | * Eric Young (eay@cryptsoft.com)" | 34 | * Eric Young (eay@cryptsoft.com)" |
35 | * The word 'cryptographic' can be left out if the rouines from the library | 35 | * The word 'cryptographic' can be left out if the rouines from the library |
36 | * being used are not cryptographic related :-). | 36 | * being used are not cryptographic related :-). |
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | 37 | * 4. If you include any Windows specific code (or a derivative thereof) from |
38 | * the apps directory (application code) you must include an acknowledgement: | 38 | * the apps directory (application code) you must include an acknowledgement: |
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" |
40 | * | 40 | * |
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND |
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
@@ -49,7 +49,7 @@ | |||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
51 | * SUCH DAMAGE. | 51 | * SUCH DAMAGE. |
52 | * | 52 | * |
53 | * The licence and distribution terms for any publically available version or | 53 | * The licence and distribution terms for any publically available version or |
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be |
55 | * copied and put under another distribution licence | 55 | * copied and put under another distribution licence |
@@ -60,55 +60,55 @@ | |||
60 | #include "cryptlib.h" | 60 | #include "cryptlib.h" |
61 | #include <openssl/asn1t.h> | 61 | #include <openssl/asn1t.h> |
62 | 62 | ||
63 | int i2d_ASN1_BOOLEAN(int a, unsigned char **pp) | 63 | int |
64 | { | 64 | i2d_ASN1_BOOLEAN(int a, unsigned char **pp) |
65 | { | ||
65 | int r; | 66 | int r; |
66 | unsigned char *p; | 67 | unsigned char *p; |
67 | 68 | ||
68 | r=ASN1_object_size(0,1,V_ASN1_BOOLEAN); | 69 | r = ASN1_object_size(0, 1, V_ASN1_BOOLEAN); |
69 | if (pp == NULL) return(r); | 70 | if (pp == NULL) |
70 | p= *pp; | 71 | return (r); |
72 | p = *pp; | ||
71 | 73 | ||
72 | ASN1_put_object(&p,0,1,V_ASN1_BOOLEAN,V_ASN1_UNIVERSAL); | 74 | ASN1_put_object(&p, 0, 1, V_ASN1_BOOLEAN, V_ASN1_UNIVERSAL); |
73 | *(p++)= (unsigned char)a; | 75 | *(p++) = (unsigned char)a; |
74 | *pp=p; | 76 | *pp = p; |
75 | return(r); | 77 | return (r); |
76 | } | 78 | } |
77 | 79 | ||
78 | int d2i_ASN1_BOOLEAN(int *a, const unsigned char **pp, long length) | 80 | int |
79 | { | 81 | d2i_ASN1_BOOLEAN(int *a, const unsigned char **pp, long length) |
80 | int ret= -1; | 82 | { |
83 | int ret = -1; | ||
81 | const unsigned char *p; | 84 | const unsigned char *p; |
82 | long len; | 85 | long len; |
83 | int inf,tag,xclass; | 86 | int inf, tag, xclass; |
84 | int i=0; | 87 | int i = 0; |
85 | 88 | ||
86 | p= *pp; | 89 | p = *pp; |
87 | inf=ASN1_get_object(&p,&len,&tag,&xclass,length); | 90 | inf = ASN1_get_object(&p, &len, &tag, &xclass, length); |
88 | if (inf & 0x80) | 91 | if (inf & 0x80) { |
89 | { | 92 | i = ASN1_R_BAD_OBJECT_HEADER; |
90 | i=ASN1_R_BAD_OBJECT_HEADER; | ||
91 | goto err; | 93 | goto err; |
92 | } | 94 | } |
93 | 95 | ||
94 | if (tag != V_ASN1_BOOLEAN) | 96 | if (tag != V_ASN1_BOOLEAN) { |
95 | { | 97 | i = ASN1_R_EXPECTING_A_BOOLEAN; |
96 | i=ASN1_R_EXPECTING_A_BOOLEAN; | ||
97 | goto err; | 98 | goto err; |
98 | } | 99 | } |
99 | 100 | ||
100 | if (len != 1) | 101 | if (len != 1) { |
101 | { | 102 | i = ASN1_R_BOOLEAN_IS_WRONG_LENGTH; |
102 | i=ASN1_R_BOOLEAN_IS_WRONG_LENGTH; | ||
103 | goto err; | 103 | goto err; |
104 | } | ||
105 | ret= (int)*(p++); | ||
106 | if (a != NULL) (*a)=ret; | ||
107 | *pp=p; | ||
108 | return(ret); | ||
109 | err: | ||
110 | ASN1err(ASN1_F_D2I_ASN1_BOOLEAN,i); | ||
111 | return(ret); | ||
112 | } | 104 | } |
105 | ret = (int)*(p++); | ||
106 | if (a != NULL) | ||
107 | (*a) = ret; | ||
108 | *pp = p; | ||
109 | return (ret); | ||
113 | 110 | ||
114 | 111 | err: | |
112 | ASN1err(ASN1_F_D2I_ASN1_BOOLEAN, i); | ||
113 | return (ret); | ||
114 | } | ||
diff --git a/src/lib/libcrypto/asn1/a_bytes.c b/src/lib/libcrypto/asn1/a_bytes.c index 8431d89edf..30647c97b5 100644 --- a/src/lib/libcrypto/asn1/a_bytes.c +++ b/src/lib/libcrypto/asn1/a_bytes.c | |||
@@ -5,21 +5,21 @@ | |||
5 | * This package is an SSL implementation written | 5 | * This package is an SSL implementation written |
6 | * by Eric Young (eay@cryptsoft.com). | 6 | * by Eric Young (eay@cryptsoft.com). |
7 | * The implementation was written so as to conform with Netscapes SSL. | 7 | * The implementation was written so as to conform with Netscapes SSL. |
8 | * | 8 | * |
9 | * This library is free for commercial and non-commercial use as long as | 9 | * This library is free for commercial and non-commercial use as long as |
10 | * the following conditions are aheared to. The following conditions | 10 | * the following conditions are aheared to. The following conditions |
11 | * apply to all code found in this distribution, be it the RC4, RSA, | 11 | * apply to all code found in this distribution, be it the RC4, RSA, |
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation |
13 | * included with this distribution is covered by the same copyright terms | 13 | * included with this distribution is covered by the same copyright terms |
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). |
15 | * | 15 | * |
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | 16 | * Copyright remains Eric Young's, and as such any Copyright notices in |
17 | * the code are not to be removed. | 17 | * the code are not to be removed. |
18 | * If this package is used in a product, Eric Young should be given attribution | 18 | * If this package is used in a product, Eric Young should be given attribution |
19 | * as the author of the parts of the library used. | 19 | * as the author of the parts of the library used. |
20 | * This can be in the form of a textual message at program startup or | 20 | * This can be in the form of a textual message at program startup or |
21 | * in documentation (online or textual) provided with the package. | 21 | * in documentation (online or textual) provided with the package. |
22 | * | 22 | * |
23 | * Redistribution and use in source and binary forms, with or without | 23 | * Redistribution and use in source and binary forms, with or without |
24 | * modification, are permitted provided that the following conditions | 24 | * modification, are permitted provided that the following conditions |
25 | * are met: | 25 | * are met: |
@@ -34,10 +34,10 @@ | |||
34 | * Eric Young (eay@cryptsoft.com)" | 34 | * Eric Young (eay@cryptsoft.com)" |
35 | * The word 'cryptographic' can be left out if the rouines from the library | 35 | * The word 'cryptographic' can be left out if the rouines from the library |
36 | * being used are not cryptographic related :-). | 36 | * being used are not cryptographic related :-). |
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | 37 | * 4. If you include any Windows specific code (or a derivative thereof) from |
38 | * the apps directory (application code) you must include an acknowledgement: | 38 | * the apps directory (application code) you must include an acknowledgement: |
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" |
40 | * | 40 | * |
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND |
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
@@ -49,7 +49,7 @@ | |||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
51 | * SUCH DAMAGE. | 51 | * SUCH DAMAGE. |
52 | * | 52 | * |
53 | * The licence and distribution terms for any publically available version or | 53 | * The licence and distribution terms for any publically available version or |
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be |
55 | * copied and put under another distribution licence | 55 | * copied and put under another distribution licence |
@@ -63,252 +63,247 @@ | |||
63 | static int asn1_collate_primitive(ASN1_STRING *a, ASN1_const_CTX *c); | 63 | static int asn1_collate_primitive(ASN1_STRING *a, ASN1_const_CTX *c); |
64 | /* type is a 'bitmap' of acceptable string types. | 64 | /* type is a 'bitmap' of acceptable string types. |
65 | */ | 65 | */ |
66 | ASN1_STRING *d2i_ASN1_type_bytes(ASN1_STRING **a, const unsigned char **pp, | 66 | ASN1_STRING * |
67 | long length, int type) | 67 | d2i_ASN1_type_bytes(ASN1_STRING **a, const unsigned char **pp, |
68 | { | 68 | long length, int type) |
69 | ASN1_STRING *ret=NULL; | 69 | { |
70 | ASN1_STRING *ret = NULL; | ||
70 | const unsigned char *p; | 71 | const unsigned char *p; |
71 | unsigned char *s; | 72 | unsigned char *s; |
72 | long len; | 73 | long len; |
73 | int inf,tag,xclass; | 74 | int inf, tag, xclass; |
74 | int i=0; | 75 | int i = 0; |
75 | 76 | ||
76 | p= *pp; | 77 | p = *pp; |
77 | inf=ASN1_get_object(&p,&len,&tag,&xclass,length); | 78 | inf = ASN1_get_object(&p, &len, &tag, &xclass, length); |
78 | if (inf & 0x80) goto err; | 79 | if (inf & 0x80) |
80 | goto err; | ||
79 | 81 | ||
80 | if (tag >= 32) | 82 | if (tag >= 32) { |
81 | { | 83 | i = ASN1_R_TAG_VALUE_TOO_HIGH; |
82 | i=ASN1_R_TAG_VALUE_TOO_HIGH; | ||
83 | goto err; | 84 | goto err; |
84 | } | 85 | } |
85 | if (!(ASN1_tag2bit(tag) & type)) | 86 | if (!(ASN1_tag2bit(tag) & type)) { |
86 | { | 87 | i = ASN1_R_WRONG_TYPE; |
87 | i=ASN1_R_WRONG_TYPE; | ||
88 | goto err; | 88 | goto err; |
89 | } | 89 | } |
90 | 90 | ||
91 | /* If a bit-string, exit early */ | 91 | /* If a bit-string, exit early */ |
92 | if (tag == V_ASN1_BIT_STRING) | 92 | if (tag == V_ASN1_BIT_STRING) |
93 | return(d2i_ASN1_BIT_STRING(a,pp,length)); | 93 | return (d2i_ASN1_BIT_STRING(a, pp, length)); |
94 | 94 | ||
95 | if ((a == NULL) || ((*a) == NULL)) | 95 | if ((a == NULL) || ((*a) == NULL)) { |
96 | { | 96 | if ((ret = ASN1_STRING_new()) == NULL) |
97 | if ((ret=ASN1_STRING_new()) == NULL) return(NULL); | 97 | return (NULL); |
98 | } | 98 | } else |
99 | else | 99 | ret = (*a); |
100 | ret=(*a); | 100 | |
101 | 101 | if (len != 0) { | |
102 | if (len != 0) | 102 | s = (unsigned char *)malloc((int)len + 1); |
103 | { | 103 | if (s == NULL) { |
104 | s=(unsigned char *)malloc((int)len+1); | 104 | i = ERR_R_MALLOC_FAILURE; |
105 | if (s == NULL) | ||
106 | { | ||
107 | i=ERR_R_MALLOC_FAILURE; | ||
108 | goto err; | 105 | goto err; |
109 | } | ||
110 | memcpy(s,p,(int)len); | ||
111 | s[len]='\0'; | ||
112 | p+=len; | ||
113 | } | 106 | } |
114 | else | 107 | memcpy(s, p, (int)len); |
115 | s=NULL; | 108 | s[len]='\0'; |
116 | 109 | p += len; | |
117 | if (ret->data != NULL) free(ret->data); | 110 | } else |
118 | ret->length=(int)len; | 111 | s = NULL; |
119 | ret->data=s; | 112 | |
120 | ret->type=tag; | 113 | if (ret->data != NULL) |
121 | if (a != NULL) (*a)=ret; | 114 | free(ret->data); |
122 | *pp=p; | 115 | ret->length = (int)len; |
123 | return(ret); | 116 | ret->data = s; |
117 | ret->type = tag; | ||
118 | if (a != NULL) | ||
119 | (*a) = ret; | ||
120 | *pp = p; | ||
121 | return (ret); | ||
122 | |||
124 | err: | 123 | err: |
125 | ASN1err(ASN1_F_D2I_ASN1_TYPE_BYTES,i); | 124 | ASN1err(ASN1_F_D2I_ASN1_TYPE_BYTES, i); |
126 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) | 125 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) |
127 | ASN1_STRING_free(ret); | 126 | ASN1_STRING_free(ret); |
128 | return(NULL); | 127 | return (NULL); |
129 | } | 128 | } |
130 | 129 | ||
131 | int i2d_ASN1_bytes(ASN1_STRING *a, unsigned char **pp, int tag, int xclass) | 130 | int |
132 | { | 131 | i2d_ASN1_bytes(ASN1_STRING *a, unsigned char **pp, int tag, int xclass) |
133 | int ret,r,constructed; | 132 | { |
133 | int ret, r, constructed; | ||
134 | unsigned char *p; | 134 | unsigned char *p; |
135 | 135 | ||
136 | if (a == NULL) return(0); | 136 | if (a == NULL) |
137 | return (0); | ||
137 | 138 | ||
138 | if (tag == V_ASN1_BIT_STRING) | 139 | if (tag == V_ASN1_BIT_STRING) |
139 | return(i2d_ASN1_BIT_STRING(a,pp)); | 140 | return (i2d_ASN1_BIT_STRING(a, pp)); |
140 | 141 | ||
141 | ret=a->length; | 142 | ret = a->length; |
142 | r=ASN1_object_size(0,ret,tag); | 143 | r = ASN1_object_size(0, ret, tag); |
143 | if (pp == NULL) return(r); | 144 | if (pp == NULL) |
144 | p= *pp; | 145 | return (r); |
146 | p = *pp; | ||
145 | 147 | ||
146 | if ((tag == V_ASN1_SEQUENCE) || (tag == V_ASN1_SET)) | 148 | if ((tag == V_ASN1_SEQUENCE) || (tag == V_ASN1_SET)) |
147 | constructed=1; | 149 | constructed = 1; |
148 | else | 150 | else |
149 | constructed=0; | 151 | constructed = 0; |
150 | ASN1_put_object(&p,constructed,ret,tag,xclass); | 152 | ASN1_put_object(&p, constructed, ret, tag, xclass); |
151 | memcpy(p,a->data,a->length); | 153 | memcpy(p, a->data, a->length); |
152 | p+=a->length; | 154 | p += a->length; |
153 | *pp= p; | 155 | *pp = p; |
154 | return(r); | 156 | return (r); |
155 | } | 157 | } |
156 | 158 | ||
157 | ASN1_STRING *d2i_ASN1_bytes(ASN1_STRING **a, const unsigned char **pp, | 159 | ASN1_STRING * |
158 | long length, int Ptag, int Pclass) | 160 | d2i_ASN1_bytes(ASN1_STRING **a, const unsigned char **pp, |
159 | { | 161 | long length, int Ptag, int Pclass) |
160 | ASN1_STRING *ret=NULL; | 162 | { |
163 | ASN1_STRING *ret = NULL; | ||
161 | const unsigned char *p; | 164 | const unsigned char *p; |
162 | unsigned char *s; | 165 | unsigned char *s; |
163 | long len; | 166 | long len; |
164 | int inf,tag,xclass; | 167 | int inf, tag, xclass; |
165 | int i=0; | 168 | int i = 0; |
166 | 169 | ||
167 | if ((a == NULL) || ((*a) == NULL)) | 170 | if ((a == NULL) || ((*a) == NULL)) { |
168 | { | 171 | if ((ret = ASN1_STRING_new()) == NULL) |
169 | if ((ret=ASN1_STRING_new()) == NULL) return(NULL); | 172 | return (NULL); |
170 | } | 173 | } else |
171 | else | 174 | ret = (*a); |
172 | ret=(*a); | ||
173 | 175 | ||
174 | p= *pp; | 176 | p= *pp; |
175 | inf=ASN1_get_object(&p,&len,&tag,&xclass,length); | 177 | inf = ASN1_get_object(&p, &len, &tag, &xclass, length); |
176 | if (inf & 0x80) | 178 | if (inf & 0x80) { |
177 | { | 179 | i = ASN1_R_BAD_OBJECT_HEADER; |
178 | i=ASN1_R_BAD_OBJECT_HEADER; | ||
179 | goto err; | 180 | goto err; |
180 | } | 181 | } |
181 | 182 | ||
182 | if (tag != Ptag) | 183 | if (tag != Ptag) { |
183 | { | 184 | i = ASN1_R_WRONG_TAG; |
184 | i=ASN1_R_WRONG_TAG; | ||
185 | goto err; | 185 | goto err; |
186 | } | 186 | } |
187 | 187 | ||
188 | if (inf & V_ASN1_CONSTRUCTED) | 188 | if (inf & V_ASN1_CONSTRUCTED) { |
189 | { | ||
190 | ASN1_const_CTX c; | 189 | ASN1_const_CTX c; |
191 | 190 | ||
192 | c.pp=pp; | 191 | c.pp = pp; |
193 | c.p=p; | 192 | c.p = p; |
194 | c.inf=inf; | 193 | c.inf = inf; |
195 | c.slen=len; | 194 | c.slen = len; |
196 | c.tag=Ptag; | 195 | c.tag = Ptag; |
197 | c.xclass=Pclass; | 196 | c.xclass = Pclass; |
198 | c.max=(length == 0)?0:(p+length); | 197 | c.max = (length == 0) ? 0 : (p + length); |
199 | if (!asn1_collate_primitive(ret,&c)) | 198 | if (!asn1_collate_primitive(ret, &c)) |
200 | goto err; | 199 | goto err; |
201 | else | 200 | else { |
202 | { | 201 | p = c.p; |
203 | p=c.p; | ||
204 | } | ||
205 | } | 202 | } |
206 | else | 203 | } else { |
207 | { | 204 | if (len != 0) { |
208 | if (len != 0) | 205 | if ((ret->length < len) || (ret->data == NULL)) { |
209 | { | 206 | if (ret->data != NULL) |
210 | if ((ret->length < len) || (ret->data == NULL)) | 207 | free(ret->data); |
211 | { | 208 | s = (unsigned char *)malloc((int)len + 1); |
212 | if (ret->data != NULL) free(ret->data); | 209 | if (s == NULL) { |
213 | s=(unsigned char *)malloc((int)len + 1); | 210 | i = ERR_R_MALLOC_FAILURE; |
214 | if (s == NULL) | ||
215 | { | ||
216 | i=ERR_R_MALLOC_FAILURE; | ||
217 | goto err; | 211 | goto err; |
218 | } | ||
219 | } | 212 | } |
220 | else | 213 | } else |
221 | s=ret->data; | 214 | s = ret->data; |
222 | memcpy(s,p,(int)len); | 215 | memcpy(s, p, (int)len); |
223 | s[len] = '\0'; | 216 | s[len] = '\0'; |
224 | p+=len; | 217 | p += len; |
225 | } | 218 | } else { |
226 | else | 219 | s = NULL; |
227 | { | 220 | if (ret->data != NULL) |
228 | s=NULL; | 221 | free(ret->data); |
229 | if (ret->data != NULL) free(ret->data); | ||
230 | } | ||
231 | |||
232 | ret->length=(int)len; | ||
233 | ret->data=s; | ||
234 | ret->type=Ptag; | ||
235 | } | 222 | } |
236 | 223 | ||
237 | if (a != NULL) (*a)=ret; | 224 | ret->length = (int)len; |
238 | *pp=p; | 225 | ret->data = s; |
239 | return(ret); | 226 | ret->type = Ptag; |
227 | } | ||
228 | |||
229 | if (a != NULL) | ||
230 | (*a) = ret; | ||
231 | *pp = p; | ||
232 | return (ret); | ||
233 | |||
240 | err: | 234 | err: |
241 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) | 235 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) |
242 | ASN1_STRING_free(ret); | 236 | ASN1_STRING_free(ret); |
243 | ASN1err(ASN1_F_D2I_ASN1_BYTES,i); | 237 | ASN1err(ASN1_F_D2I_ASN1_BYTES, i); |
244 | return(NULL); | 238 | return (NULL); |
245 | } | 239 | } |
246 | 240 | ||
247 | 241 | ||
248 | /* We are about to parse 0..n d2i_ASN1_bytes objects, we are to collapse | 242 | /* We are about to parse 0..n d2i_ASN1_bytes objects, we are to collapse |
249 | * them into the one structure that is then returned */ | 243 | * them into the one structure that is then returned */ |
250 | /* There have been a few bug fixes for this function from | 244 | /* There have been a few bug fixes for this function from |
251 | * Paul Keogh <paul.keogh@sse.ie>, many thanks to him */ | 245 | * Paul Keogh <paul.keogh@sse.ie>, many thanks to him */ |
252 | static int asn1_collate_primitive(ASN1_STRING *a, ASN1_const_CTX *c) | 246 | static int |
253 | { | 247 | asn1_collate_primitive(ASN1_STRING *a, ASN1_const_CTX *c) |
254 | ASN1_STRING *os=NULL; | 248 | { |
249 | ASN1_STRING *os = NULL; | ||
255 | BUF_MEM b; | 250 | BUF_MEM b; |
256 | int num; | 251 | int num; |
257 | 252 | ||
258 | b.length=0; | 253 | b.length = 0; |
259 | b.max=0; | 254 | b.max = 0; |
260 | b.data=NULL; | 255 | b.data = NULL; |
261 | 256 | ||
262 | if (a == NULL) | 257 | if (a == NULL) { |
263 | { | 258 | c->error = ERR_R_PASSED_NULL_PARAMETER; |
264 | c->error=ERR_R_PASSED_NULL_PARAMETER; | ||
265 | goto err; | 259 | goto err; |
260 | } | ||
261 | |||
262 | num = 0; | ||
263 | for (;;) { | ||
264 | if (c->inf & 1) { | ||
265 | c->eos = ASN1_const_check_infinite_end(&c->p, | ||
266 | (long)(c->max - c->p)); | ||
267 | if (c->eos) | ||
268 | break; | ||
269 | } else { | ||
270 | if (c->slen <= 0) | ||
271 | break; | ||
266 | } | 272 | } |
267 | 273 | ||
268 | num=0; | 274 | c->q = c->p; |
269 | for (;;) | 275 | if (d2i_ASN1_bytes(&os, &c->p, c->max - c->p, c->tag, |
270 | { | 276 | c->xclass) == NULL) { |
271 | if (c->inf & 1) | 277 | c->error = ERR_R_ASN1_LIB; |
272 | { | ||
273 | c->eos=ASN1_const_check_infinite_end(&c->p, | ||
274 | (long)(c->max-c->p)); | ||
275 | if (c->eos) break; | ||
276 | } | ||
277 | else | ||
278 | { | ||
279 | if (c->slen <= 0) break; | ||
280 | } | ||
281 | |||
282 | c->q=c->p; | ||
283 | if (d2i_ASN1_bytes(&os,&c->p,c->max-c->p,c->tag,c->xclass) | ||
284 | == NULL) | ||
285 | { | ||
286 | c->error=ERR_R_ASN1_LIB; | ||
287 | goto err; | 278 | goto err; |
288 | } | 279 | } |
289 | 280 | ||
290 | if (!BUF_MEM_grow_clean(&b,num+os->length)) | 281 | if (!BUF_MEM_grow_clean(&b, num + os->length)) { |
291 | { | 282 | c->error = ERR_R_BUF_LIB; |
292 | c->error=ERR_R_BUF_LIB; | ||
293 | goto err; | 283 | goto err; |
294 | } | ||
295 | memcpy(&(b.data[num]),os->data,os->length); | ||
296 | if (!(c->inf & 1)) | ||
297 | c->slen-=(c->p-c->q); | ||
298 | num+=os->length; | ||
299 | } | 284 | } |
285 | memcpy(&(b.data[num]), os->data, os->length); | ||
286 | if (!(c->inf & 1)) | ||
287 | c->slen -= (c->p - c->q); | ||
288 | num += os->length; | ||
289 | } | ||
290 | |||
291 | if (!asn1_const_Finish(c)) | ||
292 | goto err; | ||
300 | 293 | ||
301 | if (!asn1_const_Finish(c)) goto err; | 294 | a->length = num; |
295 | if (a->data != NULL) | ||
296 | free(a->data); | ||
297 | a->data = (unsigned char *)b.data; | ||
298 | if (os != NULL) | ||
299 | ASN1_STRING_free(os); | ||
300 | return (1); | ||
302 | 301 | ||
303 | a->length=num; | ||
304 | if (a->data != NULL) free(a->data); | ||
305 | a->data=(unsigned char *)b.data; | ||
306 | if (os != NULL) ASN1_STRING_free(os); | ||
307 | return(1); | ||
308 | err: | 302 | err: |
309 | ASN1err(ASN1_F_ASN1_COLLATE_PRIMITIVE,c->error); | 303 | ASN1err(ASN1_F_ASN1_COLLATE_PRIMITIVE, c->error); |
310 | if (os != NULL) ASN1_STRING_free(os); | 304 | if (os != NULL) |
311 | if (b.data != NULL) free(b.data); | 305 | ASN1_STRING_free(os); |
312 | return(0); | 306 | if (b.data != NULL) |
313 | } | 307 | free(b.data); |
314 | 308 | return (0); | |
309 | } | ||
diff --git a/src/lib/libcrypto/asn1/a_d2i_fp.c b/src/lib/libcrypto/asn1/a_d2i_fp.c index 52b2ebdb63..af7a4bac30 100644 --- a/src/lib/libcrypto/asn1/a_d2i_fp.c +++ b/src/lib/libcrypto/asn1/a_d2i_fp.c | |||
@@ -5,21 +5,21 @@ | |||
5 | * This package is an SSL implementation written | 5 | * This package is an SSL implementation written |
6 | * by Eric Young (eay@cryptsoft.com). | 6 | * by Eric Young (eay@cryptsoft.com). |
7 | * The implementation was written so as to conform with Netscapes SSL. | 7 | * The implementation was written so as to conform with Netscapes SSL. |
8 | * | 8 | * |
9 | * This library is free for commercial and non-commercial use as long as | 9 | * This library is free for commercial and non-commercial use as long as |
10 | * the following conditions are aheared to. The following conditions | 10 | * the following conditions are aheared to. The following conditions |
11 | * apply to all code found in this distribution, be it the RC4, RSA, | 11 | * apply to all code found in this distribution, be it the RC4, RSA, |
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation |
13 | * included with this distribution is covered by the same copyright terms | 13 | * included with this distribution is covered by the same copyright terms |
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). |
15 | * | 15 | * |
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | 16 | * Copyright remains Eric Young's, and as such any Copyright notices in |
17 | * the code are not to be removed. | 17 | * the code are not to be removed. |
18 | * If this package is used in a product, Eric Young should be given attribution | 18 | * If this package is used in a product, Eric Young should be given attribution |
19 | * as the author of the parts of the library used. | 19 | * as the author of the parts of the library used. |
20 | * This can be in the form of a textual message at program startup or | 20 | * This can be in the form of a textual message at program startup or |
21 | * in documentation (online or textual) provided with the package. | 21 | * in documentation (online or textual) provided with the package. |
22 | * | 22 | * |
23 | * Redistribution and use in source and binary forms, with or without | 23 | * Redistribution and use in source and binary forms, with or without |
24 | * modification, are permitted provided that the following conditions | 24 | * modification, are permitted provided that the following conditions |
25 | * are met: | 25 | * are met: |
@@ -34,10 +34,10 @@ | |||
34 | * Eric Young (eay@cryptsoft.com)" | 34 | * Eric Young (eay@cryptsoft.com)" |
35 | * The word 'cryptographic' can be left out if the rouines from the library | 35 | * The word 'cryptographic' can be left out if the rouines from the library |
36 | * being used are not cryptographic related :-). | 36 | * being used are not cryptographic related :-). |
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | 37 | * 4. If you include any Windows specific code (or a derivative thereof) from |
38 | * the apps directory (application code) you must include an acknowledgement: | 38 | * the apps directory (application code) you must include an acknowledgement: |
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" |
40 | * | 40 | * |
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND |
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
@@ -49,7 +49,7 @@ | |||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
51 | * SUCH DAMAGE. | 51 | * SUCH DAMAGE. |
52 | * | 52 | * |
53 | * The licence and distribution terms for any publically available version or | 53 | * The licence and distribution terms for any publically available version or |
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be |
55 | * copied and put under another distribution licence | 55 | * copied and put under another distribution licence |
@@ -67,220 +67,208 @@ static int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb); | |||
67 | #ifndef NO_OLD_ASN1 | 67 | #ifndef NO_OLD_ASN1 |
68 | #ifndef OPENSSL_NO_FP_API | 68 | #ifndef OPENSSL_NO_FP_API |
69 | 69 | ||
70 | void *ASN1_d2i_fp(void *(*xnew)(void), d2i_of_void *d2i, FILE *in, void **x) | 70 | void * |
71 | { | 71 | ASN1_d2i_fp(void *(*xnew)(void), d2i_of_void *d2i, FILE *in, void **x) |
72 | BIO *b; | 72 | { |
73 | void *ret; | 73 | BIO *b; |
74 | void *ret; | ||
74 | 75 | ||
75 | if ((b=BIO_new(BIO_s_file())) == NULL) | 76 | if ((b = BIO_new(BIO_s_file())) == NULL) { |
76 | { | 77 | ASN1err(ASN1_F_ASN1_D2I_FP, ERR_R_BUF_LIB); |
77 | ASN1err(ASN1_F_ASN1_D2I_FP,ERR_R_BUF_LIB); | 78 | return (NULL); |
78 | return(NULL); | 79 | } |
79 | } | 80 | BIO_set_fp(b, in, BIO_NOCLOSE); |
80 | BIO_set_fp(b,in,BIO_NOCLOSE); | 81 | ret = ASN1_d2i_bio(xnew, d2i, b, x); |
81 | ret=ASN1_d2i_bio(xnew,d2i,b,x); | 82 | BIO_free(b); |
82 | BIO_free(b); | 83 | return (ret); |
83 | return(ret); | 84 | } |
84 | } | ||
85 | #endif | 85 | #endif |
86 | 86 | ||
87 | void *ASN1_d2i_bio(void *(*xnew)(void), d2i_of_void *d2i, BIO *in, void **x) | 87 | void * |
88 | { | 88 | ASN1_d2i_bio(void *(*xnew)(void), d2i_of_void *d2i, BIO *in, void **x) |
89 | { | ||
89 | BUF_MEM *b = NULL; | 90 | BUF_MEM *b = NULL; |
90 | const unsigned char *p; | 91 | const unsigned char *p; |
91 | void *ret=NULL; | 92 | void *ret = NULL; |
92 | int len; | 93 | int len; |
93 | 94 | ||
94 | len = asn1_d2i_read_bio(in, &b); | 95 | len = asn1_d2i_read_bio(in, &b); |
95 | if(len < 0) goto err; | 96 | if (len < 0) |
97 | goto err; | ||
98 | |||
99 | p = (unsigned char *)b->data; | ||
100 | ret = d2i(x, &p, len); | ||
96 | 101 | ||
97 | p=(unsigned char *)b->data; | ||
98 | ret=d2i(x,&p,len); | ||
99 | err: | 102 | err: |
100 | if (b != NULL) BUF_MEM_free(b); | 103 | if (b != NULL) |
101 | return(ret); | 104 | BUF_MEM_free(b); |
102 | } | 105 | return (ret); |
106 | } | ||
103 | 107 | ||
104 | #endif | 108 | #endif |
105 | 109 | ||
106 | void *ASN1_item_d2i_bio(const ASN1_ITEM *it, BIO *in, void *x) | 110 | void * |
107 | { | 111 | ASN1_item_d2i_bio(const ASN1_ITEM *it, BIO *in, void *x) |
112 | { | ||
108 | BUF_MEM *b = NULL; | 113 | BUF_MEM *b = NULL; |
109 | const unsigned char *p; | 114 | const unsigned char *p; |
110 | void *ret=NULL; | 115 | void *ret = NULL; |
111 | int len; | 116 | int len; |
112 | 117 | ||
113 | len = asn1_d2i_read_bio(in, &b); | 118 | len = asn1_d2i_read_bio(in, &b); |
114 | if(len < 0) goto err; | 119 | if (len < 0) |
120 | goto err; | ||
121 | |||
122 | p = (const unsigned char *)b->data; | ||
123 | ret = ASN1_item_d2i(x, &p, len, it); | ||
115 | 124 | ||
116 | p=(const unsigned char *)b->data; | ||
117 | ret=ASN1_item_d2i(x,&p,len, it); | ||
118 | err: | 125 | err: |
119 | if (b != NULL) BUF_MEM_free(b); | 126 | if (b != NULL) |
120 | return(ret); | 127 | BUF_MEM_free(b); |
121 | } | 128 | return (ret); |
129 | } | ||
122 | 130 | ||
123 | #ifndef OPENSSL_NO_FP_API | 131 | #ifndef OPENSSL_NO_FP_API |
124 | void *ASN1_item_d2i_fp(const ASN1_ITEM *it, FILE *in, void *x) | 132 | void * |
125 | { | 133 | ASN1_item_d2i_fp(const ASN1_ITEM *it, FILE *in, void *x) |
126 | BIO *b; | 134 | { |
127 | char *ret; | 135 | BIO *b; |
136 | char *ret; | ||
128 | 137 | ||
129 | if ((b=BIO_new(BIO_s_file())) == NULL) | 138 | if ((b = BIO_new(BIO_s_file())) == NULL) { |
130 | { | 139 | ASN1err(ASN1_F_ASN1_ITEM_D2I_FP, ERR_R_BUF_LIB); |
131 | ASN1err(ASN1_F_ASN1_ITEM_D2I_FP,ERR_R_BUF_LIB); | 140 | return (NULL); |
132 | return(NULL); | 141 | } |
133 | } | 142 | BIO_set_fp(b, in, BIO_NOCLOSE); |
134 | BIO_set_fp(b,in,BIO_NOCLOSE); | 143 | ret = ASN1_item_d2i_bio(it, b, x); |
135 | ret=ASN1_item_d2i_bio(it,b,x); | 144 | BIO_free(b); |
136 | BIO_free(b); | 145 | return (ret); |
137 | return(ret); | 146 | } |
138 | } | ||
139 | #endif | 147 | #endif |
140 | 148 | ||
141 | #define HEADER_SIZE 8 | 149 | #define HEADER_SIZE 8 |
142 | static int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb) | 150 | static int |
143 | { | 151 | asn1_d2i_read_bio(BIO *in, BUF_MEM **pb) |
152 | { | ||
144 | BUF_MEM *b; | 153 | BUF_MEM *b; |
145 | unsigned char *p; | 154 | unsigned char *p; |
146 | int i; | 155 | int i; |
147 | ASN1_const_CTX c; | 156 | ASN1_const_CTX c; |
148 | size_t want=HEADER_SIZE; | 157 | size_t want = HEADER_SIZE; |
149 | int eos=0; | 158 | int eos = 0; |
150 | size_t off=0; | 159 | size_t off = 0; |
151 | size_t len=0; | 160 | size_t len = 0; |
152 | 161 | ||
153 | b=BUF_MEM_new(); | 162 | b = BUF_MEM_new(); |
154 | if (b == NULL) | 163 | if (b == NULL) { |
155 | { | 164 | ASN1err(ASN1_F_ASN1_D2I_READ_BIO, ERR_R_MALLOC_FAILURE); |
156 | ASN1err(ASN1_F_ASN1_D2I_READ_BIO,ERR_R_MALLOC_FAILURE); | ||
157 | return -1; | 165 | return -1; |
158 | } | 166 | } |
159 | 167 | ||
160 | ERR_clear_error(); | 168 | ERR_clear_error(); |
161 | for (;;) | 169 | for (;;) { |
162 | { | 170 | if (want >= (len - off)) { |
163 | if (want >= (len-off)) | 171 | want -= (len - off); |
164 | { | ||
165 | want-=(len-off); | ||
166 | 172 | ||
167 | if (len + want < len || !BUF_MEM_grow_clean(b,len+want)) | 173 | if (len + want < len || !BUF_MEM_grow_clean(b, len + want)) { |
168 | { | 174 | ASN1err(ASN1_F_ASN1_D2I_READ_BIO, ERR_R_MALLOC_FAILURE); |
169 | ASN1err(ASN1_F_ASN1_D2I_READ_BIO,ERR_R_MALLOC_FAILURE); | ||
170 | goto err; | 175 | goto err; |
171 | } | 176 | } |
172 | i=BIO_read(in,&(b->data[len]),want); | 177 | i = BIO_read(in, &(b->data[len]), want); |
173 | if ((i < 0) && ((len-off) == 0)) | 178 | if ((i < 0) && ((len - off) == 0)) { |
174 | { | 179 | ASN1err(ASN1_F_ASN1_D2I_READ_BIO, ASN1_R_NOT_ENOUGH_DATA); |
175 | ASN1err(ASN1_F_ASN1_D2I_READ_BIO,ASN1_R_NOT_ENOUGH_DATA); | ||
176 | goto err; | 180 | goto err; |
177 | } | 181 | } |
178 | if (i > 0) | 182 | if (i > 0) { |
179 | { | 183 | if (len + i < len) { |
180 | if (len+i < len) | 184 | ASN1err(ASN1_F_ASN1_D2I_READ_BIO, ASN1_R_TOO_LONG); |
181 | { | ||
182 | ASN1err(ASN1_F_ASN1_D2I_READ_BIO,ASN1_R_TOO_LONG); | ||
183 | goto err; | 185 | goto err; |
184 | } | ||
185 | len+=i; | ||
186 | } | 186 | } |
187 | len += i; | ||
187 | } | 188 | } |
189 | } | ||
188 | /* else data already loaded */ | 190 | /* else data already loaded */ |
189 | 191 | ||
190 | p=(unsigned char *)&(b->data[off]); | 192 | p = (unsigned char *) & (b->data[off]); |
191 | c.p=p; | 193 | c.p = p; |
192 | c.inf=ASN1_get_object(&(c.p),&(c.slen),&(c.tag),&(c.xclass), | 194 | c.inf = ASN1_get_object(&(c.p), &(c.slen), &(c.tag), |
193 | len-off); | 195 | &(c.xclass), len - off); |
194 | if (c.inf & 0x80) | 196 | if (c.inf & 0x80) { |
195 | { | ||
196 | unsigned long e; | 197 | unsigned long e; |
197 | 198 | ||
198 | e=ERR_GET_REASON(ERR_peek_error()); | 199 | e = ERR_GET_REASON(ERR_peek_error()); |
199 | if (e != ASN1_R_TOO_LONG) | 200 | if (e != ASN1_R_TOO_LONG) |
200 | goto err; | 201 | goto err; |
201 | else | 202 | else |
202 | ERR_clear_error(); /* clear error */ | 203 | ERR_clear_error(); /* clear error */ |
203 | } | 204 | } |
204 | i=c.p-p;/* header length */ | 205 | i = c.p - p; /* header length */ |
205 | off+=i; /* end of data */ | 206 | off += i; /* end of data */ |
206 | 207 | ||
207 | if (c.inf & 1) | 208 | if (c.inf & 1) { |
208 | { | ||
209 | /* no data body so go round again */ | 209 | /* no data body so go round again */ |
210 | eos++; | 210 | eos++; |
211 | if (eos < 0) | 211 | if (eos < 0) { |
212 | { | 212 | ASN1err(ASN1_F_ASN1_D2I_READ_BIO, ASN1_R_HEADER_TOO_LONG); |
213 | ASN1err(ASN1_F_ASN1_D2I_READ_BIO,ASN1_R_HEADER_TOO_LONG); | ||
214 | goto err; | 213 | goto err; |
215 | } | ||
216 | want=HEADER_SIZE; | ||
217 | } | 214 | } |
218 | else if (eos && (c.slen == 0) && (c.tag == V_ASN1_EOC)) | 215 | want = HEADER_SIZE; |
219 | { | 216 | } else if (eos && (c.slen == 0) && (c.tag == V_ASN1_EOC)) { |
220 | /* eos value, so go back and read another header */ | 217 | /* eos value, so go back and read another header */ |
221 | eos--; | 218 | eos--; |
222 | if (eos <= 0) | 219 | if (eos <= 0) |
223 | break; | 220 | break; |
224 | else | 221 | else |
225 | want=HEADER_SIZE; | 222 | want = HEADER_SIZE; |
226 | } | 223 | } else { |
227 | else | ||
228 | { | ||
229 | /* suck in c.slen bytes of data */ | 224 | /* suck in c.slen bytes of data */ |
230 | want=c.slen; | 225 | want = c.slen; |
231 | if (want > (len-off)) | 226 | if (want > (len - off)) { |
232 | { | 227 | want -= (len - off); |
233 | want-=(len-off); | ||
234 | if (want > INT_MAX /* BIO_read takes an int length */ || | 228 | if (want > INT_MAX /* BIO_read takes an int length */ || |
235 | len+want < len) | 229 | len+want < len) { |
236 | { | 230 | ASN1err(ASN1_F_ASN1_D2I_READ_BIO, ASN1_R_TOO_LONG); |
237 | ASN1err(ASN1_F_ASN1_D2I_READ_BIO,ASN1_R_TOO_LONG); | ||
238 | goto err; | ||
239 | } | ||
240 | if (!BUF_MEM_grow_clean(b,len+want)) | ||
241 | { | ||
242 | ASN1err(ASN1_F_ASN1_D2I_READ_BIO,ERR_R_MALLOC_FAILURE); | ||
243 | goto err; | 231 | goto err; |
244 | } | 232 | } |
245 | while (want > 0) | 233 | if (!BUF_MEM_grow_clean(b, len + want)) { |
246 | { | 234 | ASN1err(ASN1_F_ASN1_D2I_READ_BIO, ERR_R_MALLOC_FAILURE); |
247 | i=BIO_read(in,&(b->data[len]),want); | 235 | goto err; |
248 | if (i <= 0) | 236 | } |
249 | { | 237 | while (want > 0) { |
238 | i = BIO_read(in, &(b->data[len]), want); | ||
239 | if (i <= 0) { | ||
250 | ASN1err(ASN1_F_ASN1_D2I_READ_BIO, | 240 | ASN1err(ASN1_F_ASN1_D2I_READ_BIO, |
251 | ASN1_R_NOT_ENOUGH_DATA); | 241 | ASN1_R_NOT_ENOUGH_DATA); |
252 | goto err; | 242 | goto err; |
253 | } | 243 | } |
254 | /* This can't overflow because | 244 | /* This can't overflow because |
255 | * |len+want| didn't overflow. */ | 245 | * |len+want| didn't overflow. */ |
256 | len+=i; | 246 | len += i; |
257 | want-=i; | 247 | want -= i; |
258 | } | ||
259 | } | 248 | } |
260 | if (off + c.slen < off) | 249 | } |
261 | { | 250 | if (off + c.slen < off) { |
262 | ASN1err(ASN1_F_ASN1_D2I_READ_BIO,ASN1_R_TOO_LONG); | 251 | ASN1err(ASN1_F_ASN1_D2I_READ_BIO, ASN1_R_TOO_LONG); |
263 | goto err; | 252 | goto err; |
264 | } | ||
265 | off+=c.slen; | ||
266 | if (eos <= 0) | ||
267 | { | ||
268 | break; | ||
269 | } | ||
270 | else | ||
271 | want=HEADER_SIZE; | ||
272 | } | 253 | } |
254 | off += c.slen; | ||
255 | if (eos <= 0) { | ||
256 | break; | ||
257 | } else | ||
258 | want = HEADER_SIZE; | ||
273 | } | 259 | } |
260 | } | ||
274 | 261 | ||
275 | if (off > INT_MAX) | 262 | if (off > INT_MAX) { |
276 | { | 263 | ASN1err(ASN1_F_ASN1_D2I_READ_BIO, ASN1_R_TOO_LONG); |
277 | ASN1err(ASN1_F_ASN1_D2I_READ_BIO,ASN1_R_TOO_LONG); | ||
278 | goto err; | 264 | goto err; |
279 | } | 265 | } |
280 | 266 | ||
281 | *pb = b; | 267 | *pb = b; |
282 | return off; | 268 | return off; |
269 | |||
283 | err: | 270 | err: |
284 | if (b != NULL) BUF_MEM_free(b); | 271 | if (b != NULL) |
272 | BUF_MEM_free(b); | ||
285 | return -1; | 273 | return -1; |
286 | } | 274 | } |
diff --git a/src/lib/libssl/src/crypto/asn1/a_bitstr.c b/src/lib/libssl/src/crypto/asn1/a_bitstr.c index e2b65bf2ac..5633cfca1c 100644 --- a/src/lib/libssl/src/crypto/asn1/a_bitstr.c +++ b/src/lib/libssl/src/crypto/asn1/a_bitstr.c | |||
@@ -5,21 +5,21 @@ | |||
5 | * This package is an SSL implementation written | 5 | * This package is an SSL implementation written |
6 | * by Eric Young (eay@cryptsoft.com). | 6 | * by Eric Young (eay@cryptsoft.com). |
7 | * The implementation was written so as to conform with Netscapes SSL. | 7 | * The implementation was written so as to conform with Netscapes SSL. |
8 | * | 8 | * |
9 | * This library is free for commercial and non-commercial use as long as | 9 | * This library is free for commercial and non-commercial use as long as |
10 | * the following conditions are aheared to. The following conditions | 10 | * the following conditions are aheared to. The following conditions |
11 | * apply to all code found in this distribution, be it the RC4, RSA, | 11 | * apply to all code found in this distribution, be it the RC4, RSA, |
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation |
13 | * included with this distribution is covered by the same copyright terms | 13 | * included with this distribution is covered by the same copyright terms |
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). |
15 | * | 15 | * |
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | 16 | * Copyright remains Eric Young's, and as such any Copyright notices in |
17 | * the code are not to be removed. | 17 | * the code are not to be removed. |
18 | * If this package is used in a product, Eric Young should be given attribution | 18 | * If this package is used in a product, Eric Young should be given attribution |
19 | * as the author of the parts of the library used. | 19 | * as the author of the parts of the library used. |
20 | * This can be in the form of a textual message at program startup or | 20 | * This can be in the form of a textual message at program startup or |
21 | * in documentation (online or textual) provided with the package. | 21 | * in documentation (online or textual) provided with the package. |
22 | * | 22 | * |
23 | * Redistribution and use in source and binary forms, with or without | 23 | * Redistribution and use in source and binary forms, with or without |
24 | * modification, are permitted provided that the following conditions | 24 | * modification, are permitted provided that the following conditions |
25 | * are met: | 25 | * are met: |
@@ -34,10 +34,10 @@ | |||
34 | * Eric Young (eay@cryptsoft.com)" | 34 | * Eric Young (eay@cryptsoft.com)" |
35 | * The word 'cryptographic' can be left out if the rouines from the library | 35 | * The word 'cryptographic' can be left out if the rouines from the library |
36 | * being used are not cryptographic related :-). | 36 | * being used are not cryptographic related :-). |
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | 37 | * 4. If you include any Windows specific code (or a derivative thereof) from |
38 | * the apps directory (application code) you must include an acknowledgement: | 38 | * the apps directory (application code) you must include an acknowledgement: |
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" |
40 | * | 40 | * |
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND |
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
@@ -49,7 +49,7 @@ | |||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
51 | * SUCH DAMAGE. | 51 | * SUCH DAMAGE. |
52 | * | 52 | * |
53 | * The licence and distribution terms for any publically available version or | 53 | * The licence and distribution terms for any publically available version or |
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be |
55 | * copied and put under another distribution licence | 55 | * copied and put under another distribution licence |
@@ -60,82 +60,91 @@ | |||
60 | #include "cryptlib.h" | 60 | #include "cryptlib.h" |
61 | #include <openssl/asn1.h> | 61 | #include <openssl/asn1.h> |
62 | 62 | ||
63 | int ASN1_BIT_STRING_set(ASN1_BIT_STRING *x, unsigned char *d, int len) | 63 | int |
64 | { return M_ASN1_BIT_STRING_set(x, d, len); } | 64 | ASN1_BIT_STRING_set(ASN1_BIT_STRING *x, unsigned char *d, int len) |
65 | { | ||
66 | return M_ASN1_BIT_STRING_set(x, d, len); | ||
67 | } | ||
65 | 68 | ||
66 | int i2c_ASN1_BIT_STRING(ASN1_BIT_STRING *a, unsigned char **pp) | 69 | int |
67 | { | 70 | i2c_ASN1_BIT_STRING(ASN1_BIT_STRING *a, unsigned char **pp) |
68 | int ret,j,bits,len; | 71 | { |
69 | unsigned char *p,*d; | 72 | int ret, j,bits, len; |
73 | unsigned char *p, *d; | ||
70 | 74 | ||
71 | if (a == NULL) return(0); | 75 | if (a == NULL) |
76 | return (0); | ||
72 | 77 | ||
73 | len=a->length; | 78 | len = a->length; |
74 | 79 | ||
75 | if (len > 0) | 80 | if (len > 0) { |
76 | { | 81 | if (a->flags & ASN1_STRING_FLAG_BITS_LEFT) { |
77 | if (a->flags & ASN1_STRING_FLAG_BITS_LEFT) | 82 | bits = (int)a->flags & 0x07; |
78 | { | 83 | } else { |
79 | bits=(int)a->flags&0x07; | 84 | for (; len > 0; len--) { |
80 | } | 85 | if (a->data[len - 1]) |
81 | else | 86 | break; |
82 | { | ||
83 | for ( ; len > 0; len--) | ||
84 | { | ||
85 | if (a->data[len-1]) break; | ||
86 | } | ||
87 | j=a->data[len-1]; | ||
88 | if (j & 0x01) bits=0; | ||
89 | else if (j & 0x02) bits=1; | ||
90 | else if (j & 0x04) bits=2; | ||
91 | else if (j & 0x08) bits=3; | ||
92 | else if (j & 0x10) bits=4; | ||
93 | else if (j & 0x20) bits=5; | ||
94 | else if (j & 0x40) bits=6; | ||
95 | else if (j & 0x80) bits=7; | ||
96 | else bits=0; /* should not happen */ | ||
97 | } | 87 | } |
88 | j = a->data[len - 1]; | ||
89 | if (j & 0x01) | ||
90 | bits = 0; | ||
91 | else if (j & 0x02) | ||
92 | bits = 1; | ||
93 | else if (j & 0x04) | ||
94 | bits = 2; | ||
95 | else if (j & 0x08) | ||
96 | bits = 3; | ||
97 | else if (j & 0x10) | ||
98 | bits = 4; | ||
99 | else if (j & 0x20) | ||
100 | bits = 5; | ||
101 | else if (j & 0x40) | ||
102 | bits = 6; | ||
103 | else if (j & 0x80) | ||
104 | bits = 7; | ||
105 | else | ||
106 | bits = 0; /* should not happen */ | ||
98 | } | 107 | } |
99 | else | 108 | } else |
100 | bits=0; | 109 | bits = 0; |
101 | 110 | ||
102 | ret=1+len; | 111 | ret = 1 + len; |
103 | if (pp == NULL) return(ret); | 112 | if (pp == NULL) |
113 | return (ret); | ||
104 | 114 | ||
105 | p= *pp; | 115 | p= *pp; |
106 | 116 | ||
107 | *(p++)=(unsigned char)bits; | 117 | *(p++) = (unsigned char)bits; |
108 | d=a->data; | 118 | d = a->data; |
109 | memcpy(p,d,len); | 119 | memcpy(p, d, len); |
110 | p+=len; | 120 | p += len; |
111 | if (len > 0) p[-1]&=(0xff<<bits); | 121 | if (len > 0) |
112 | *pp=p; | 122 | p[-1]&=(0xff << bits); |
113 | return(ret); | 123 | *pp = p; |
114 | } | 124 | return (ret); |
125 | } | ||
115 | 126 | ||
116 | ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a, | 127 | ASN1_BIT_STRING * |
117 | const unsigned char **pp, long len) | 128 | c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a, const unsigned char **pp, long len) |
118 | { | 129 | { |
119 | ASN1_BIT_STRING *ret=NULL; | 130 | ASN1_BIT_STRING *ret = NULL; |
120 | const unsigned char *p; | 131 | const unsigned char *p; |
121 | unsigned char *s; | 132 | unsigned char *s; |
122 | int i; | 133 | int i; |
123 | 134 | ||
124 | if (len < 1) | 135 | if (len < 1) { |
125 | { | 136 | i = ASN1_R_STRING_TOO_SHORT; |
126 | i=ASN1_R_STRING_TOO_SHORT; | ||
127 | goto err; | 137 | goto err; |
128 | } | 138 | } |
129 | 139 | ||
130 | if ((a == NULL) || ((*a) == NULL)) | 140 | if ((a == NULL) || ((*a) == NULL)) { |
131 | { | 141 | if ((ret = M_ASN1_BIT_STRING_new()) == NULL) |
132 | if ((ret=M_ASN1_BIT_STRING_new()) == NULL) return(NULL); | 142 | return (NULL); |
133 | } | 143 | } else |
134 | else | 144 | ret = (*a); |
135 | ret=(*a); | ||
136 | 145 | ||
137 | p= *pp; | 146 | p = *pp; |
138 | i= *(p++); | 147 | i = *(p++); |
139 | /* We do this to preserve the settings. If we modify | 148 | /* We do this to preserve the settings. If we modify |
140 | * the settings, via the _set_bit function, we will recalculate | 149 | * the settings, via the _set_bit function, we will recalculate |
141 | * on output */ | 150 | * on output */ |
@@ -143,106 +152,111 @@ ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a, | |||
143 | ret->flags|=(ASN1_STRING_FLAG_BITS_LEFT|(i&0x07)); /* set */ | 152 | ret->flags|=(ASN1_STRING_FLAG_BITS_LEFT|(i&0x07)); /* set */ |
144 | 153 | ||
145 | if (len-- > 1) /* using one because of the bits left byte */ | 154 | if (len-- > 1) /* using one because of the bits left byte */ |
146 | { | 155 | { |
147 | s=(unsigned char *)malloc((int)len); | 156 | s = (unsigned char *)malloc((int)len); |
148 | if (s == NULL) | 157 | if (s == NULL) { |
149 | { | 158 | i = ERR_R_MALLOC_FAILURE; |
150 | i=ERR_R_MALLOC_FAILURE; | ||
151 | goto err; | 159 | goto err; |
152 | } | ||
153 | memcpy(s,p,(int)len); | ||
154 | s[len-1]&=(0xff<<i); | ||
155 | p+=len; | ||
156 | } | 160 | } |
157 | else | 161 | memcpy(s, p, (int)len); |
158 | s=NULL; | 162 | s[len - 1] &= (0xff << i); |
159 | 163 | p += len; | |
160 | ret->length=(int)len; | 164 | } else |
161 | if (ret->data != NULL) free(ret->data); | 165 | s = NULL; |
162 | ret->data=s; | 166 | |
163 | ret->type=V_ASN1_BIT_STRING; | 167 | ret->length = (int)len; |
164 | if (a != NULL) (*a)=ret; | 168 | if (ret->data != NULL) |
165 | *pp=p; | 169 | free(ret->data); |
166 | return(ret); | 170 | ret->data = s; |
171 | ret->type = V_ASN1_BIT_STRING; | ||
172 | if (a != NULL) | ||
173 | (*a) = ret; | ||
174 | *pp = p; | ||
175 | return (ret); | ||
176 | |||
167 | err: | 177 | err: |
168 | ASN1err(ASN1_F_C2I_ASN1_BIT_STRING,i); | 178 | ASN1err(ASN1_F_C2I_ASN1_BIT_STRING, i); |
169 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) | 179 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) |
170 | M_ASN1_BIT_STRING_free(ret); | 180 | M_ASN1_BIT_STRING_free(ret); |
171 | return(NULL); | 181 | return (NULL); |
172 | } | 182 | } |
173 | 183 | ||
174 | /* These next 2 functions from Goetz Babin-Ebell <babinebell@trustcenter.de> | 184 | /* These next 2 functions from Goetz Babin-Ebell <babinebell@trustcenter.de> |
175 | */ | 185 | */ |
176 | int ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value) | 186 | int |
177 | { | 187 | ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value) |
178 | int w,v,iv; | 188 | { |
189 | int w, v, iv; | ||
179 | unsigned char *c; | 190 | unsigned char *c; |
180 | 191 | ||
181 | w=n/8; | 192 | w = n/8; |
182 | v=1<<(7-(n&0x07)); | 193 | v = 1 << (7 - (n & 0x07)); |
183 | iv= ~v; | 194 | iv = ~v; |
184 | if (!value) v=0; | 195 | if (!value) |
196 | v = 0; | ||
185 | 197 | ||
186 | if (a == NULL) | 198 | if (a == NULL) |
187 | return 0; | 199 | return 0; |
188 | 200 | ||
189 | a->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); /* clear, set on write */ | 201 | a->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); /* clear, set on write */ |
190 | 202 | ||
191 | if ((a->length < (w+1)) || (a->data == NULL)) | 203 | if ((a->length < (w + 1)) || (a->data == NULL)) { |
192 | { | 204 | if (!value) |
193 | if (!value) return(1); /* Don't need to set */ | 205 | return(1); /* Don't need to set */ |
194 | if (a->data == NULL) | 206 | if (a->data == NULL) |
195 | c=(unsigned char *)malloc(w+1); | 207 | c = (unsigned char *)malloc(w + 1); |
196 | else | 208 | else |
197 | c=(unsigned char *)OPENSSL_realloc_clean(a->data, | 209 | c = (unsigned char *)OPENSSL_realloc_clean(a->data, |
198 | a->length, | 210 | a->length, w + 1); |
199 | w+1); | 211 | if (c == NULL) { |
200 | if (c == NULL) | 212 | ASN1err(ASN1_F_ASN1_BIT_STRING_SET_BIT, ERR_R_MALLOC_FAILURE); |
201 | { | ||
202 | ASN1err(ASN1_F_ASN1_BIT_STRING_SET_BIT,ERR_R_MALLOC_FAILURE); | ||
203 | return 0; | 213 | return 0; |
204 | } | 214 | } |
205 | if (w+1-a->length > 0) memset(c+a->length, 0, w+1-a->length); | 215 | if (w + 1 - a->length > 0) |
206 | a->data=c; | 216 | memset(c + a->length, 0, w + 1 - a->length); |
207 | a->length=w+1; | 217 | a->data = c; |
218 | a->length = w + 1; | ||
208 | } | 219 | } |
209 | a->data[w]=((a->data[w])&iv)|v; | 220 | a->data[w] = ((a->data[w]) & iv) | v; |
210 | while ((a->length > 0) && (a->data[a->length-1] == 0)) | 221 | while ((a->length > 0) && (a->data[a->length - 1] == 0)) |
211 | a->length--; | 222 | a->length--; |
212 | return(1); | ||
213 | } | ||
214 | 223 | ||
215 | int ASN1_BIT_STRING_get_bit(ASN1_BIT_STRING *a, int n) | 224 | return (1); |
216 | { | 225 | } |
217 | int w,v; | ||
218 | 226 | ||
219 | w=n/8; | 227 | int |
220 | v=1<<(7-(n&0x07)); | 228 | ASN1_BIT_STRING_get_bit(ASN1_BIT_STRING *a, int n) |
221 | if ((a == NULL) || (a->length < (w+1)) || (a->data == NULL)) | 229 | { |
222 | return(0); | 230 | int w, v; |
223 | return((a->data[w]&v) != 0); | 231 | |
224 | } | 232 | w = n / 8; |
233 | v = 1 << (7 - (n & 0x07)); | ||
234 | if ((a == NULL) || (a->length < (w + 1)) || (a->data == NULL)) | ||
235 | return (0); | ||
236 | return ((a->data[w] & v) != 0); | ||
237 | } | ||
225 | 238 | ||
226 | /* | 239 | /* |
227 | * Checks if the given bit string contains only bits specified by | 240 | * Checks if the given bit string contains only bits specified by |
228 | * the flags vector. Returns 0 if there is at least one bit set in 'a' | 241 | * the flags vector. Returns 0 if there is at least one bit set in 'a' |
229 | * which is not specified in 'flags', 1 otherwise. | 242 | * which is not specified in 'flags', 1 otherwise. |
230 | * 'len' is the length of 'flags'. | 243 | * 'len' is the length of 'flags'. |
231 | */ | 244 | */ |
232 | int ASN1_BIT_STRING_check(ASN1_BIT_STRING *a, | 245 | int |
233 | unsigned char *flags, int flags_len) | 246 | ASN1_BIT_STRING_check(ASN1_BIT_STRING *a, unsigned char *flags, int flags_len) |
234 | { | 247 | { |
235 | int i, ok; | 248 | int i, ok; |
249 | |||
236 | /* Check if there is one bit set at all. */ | 250 | /* Check if there is one bit set at all. */ |
237 | if (!a || !a->data) return 1; | 251 | if (!a || !a->data) |
252 | return 1; | ||
238 | 253 | ||
239 | /* Check each byte of the internal representation of the bit string. */ | 254 | /* Check each byte of the internal representation of the bit string. */ |
240 | ok = 1; | 255 | ok = 1; |
241 | for (i = 0; i < a->length && ok; ++i) | 256 | for (i = 0; i < a->length && ok; ++i) { |
242 | { | ||
243 | unsigned char mask = i < flags_len ? ~flags[i] : 0xff; | 257 | unsigned char mask = i < flags_len ? ~flags[i] : 0xff; |
244 | /* We are done if there is an unneeded bit set. */ | 258 | /* We are done if there is an unneeded bit set. */ |
245 | ok = (a->data[i] & mask) == 0; | 259 | ok = (a->data[i] & mask) == 0; |
246 | } | ||
247 | return ok; | ||
248 | } | 260 | } |
261 | return ok; | ||
262 | } | ||
diff --git a/src/lib/libssl/src/crypto/asn1/a_bool.c b/src/lib/libssl/src/crypto/asn1/a_bool.c index 331acdf053..c8c180d6f7 100644 --- a/src/lib/libssl/src/crypto/asn1/a_bool.c +++ b/src/lib/libssl/src/crypto/asn1/a_bool.c | |||
@@ -5,21 +5,21 @@ | |||
5 | * This package is an SSL implementation written | 5 | * This package is an SSL implementation written |
6 | * by Eric Young (eay@cryptsoft.com). | 6 | * by Eric Young (eay@cryptsoft.com). |
7 | * The implementation was written so as to conform with Netscapes SSL. | 7 | * The implementation was written so as to conform with Netscapes SSL. |
8 | * | 8 | * |
9 | * This library is free for commercial and non-commercial use as long as | 9 | * This library is free for commercial and non-commercial use as long as |
10 | * the following conditions are aheared to. The following conditions | 10 | * the following conditions are aheared to. The following conditions |
11 | * apply to all code found in this distribution, be it the RC4, RSA, | 11 | * apply to all code found in this distribution, be it the RC4, RSA, |
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation |
13 | * included with this distribution is covered by the same copyright terms | 13 | * included with this distribution is covered by the same copyright terms |
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). |
15 | * | 15 | * |
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | 16 | * Copyright remains Eric Young's, and as such any Copyright notices in |
17 | * the code are not to be removed. | 17 | * the code are not to be removed. |
18 | * If this package is used in a product, Eric Young should be given attribution | 18 | * If this package is used in a product, Eric Young should be given attribution |
19 | * as the author of the parts of the library used. | 19 | * as the author of the parts of the library used. |
20 | * This can be in the form of a textual message at program startup or | 20 | * This can be in the form of a textual message at program startup or |
21 | * in documentation (online or textual) provided with the package. | 21 | * in documentation (online or textual) provided with the package. |
22 | * | 22 | * |
23 | * Redistribution and use in source and binary forms, with or without | 23 | * Redistribution and use in source and binary forms, with or without |
24 | * modification, are permitted provided that the following conditions | 24 | * modification, are permitted provided that the following conditions |
25 | * are met: | 25 | * are met: |
@@ -34,10 +34,10 @@ | |||
34 | * Eric Young (eay@cryptsoft.com)" | 34 | * Eric Young (eay@cryptsoft.com)" |
35 | * The word 'cryptographic' can be left out if the rouines from the library | 35 | * The word 'cryptographic' can be left out if the rouines from the library |
36 | * being used are not cryptographic related :-). | 36 | * being used are not cryptographic related :-). |
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | 37 | * 4. If you include any Windows specific code (or a derivative thereof) from |
38 | * the apps directory (application code) you must include an acknowledgement: | 38 | * the apps directory (application code) you must include an acknowledgement: |
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" |
40 | * | 40 | * |
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND |
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
@@ -49,7 +49,7 @@ | |||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
51 | * SUCH DAMAGE. | 51 | * SUCH DAMAGE. |
52 | * | 52 | * |
53 | * The licence and distribution terms for any publically available version or | 53 | * The licence and distribution terms for any publically available version or |
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be |
55 | * copied and put under another distribution licence | 55 | * copied and put under another distribution licence |
@@ -60,55 +60,55 @@ | |||
60 | #include "cryptlib.h" | 60 | #include "cryptlib.h" |
61 | #include <openssl/asn1t.h> | 61 | #include <openssl/asn1t.h> |
62 | 62 | ||
63 | int i2d_ASN1_BOOLEAN(int a, unsigned char **pp) | 63 | int |
64 | { | 64 | i2d_ASN1_BOOLEAN(int a, unsigned char **pp) |
65 | { | ||
65 | int r; | 66 | int r; |
66 | unsigned char *p; | 67 | unsigned char *p; |
67 | 68 | ||
68 | r=ASN1_object_size(0,1,V_ASN1_BOOLEAN); | 69 | r = ASN1_object_size(0, 1, V_ASN1_BOOLEAN); |
69 | if (pp == NULL) return(r); | 70 | if (pp == NULL) |
70 | p= *pp; | 71 | return (r); |
72 | p = *pp; | ||
71 | 73 | ||
72 | ASN1_put_object(&p,0,1,V_ASN1_BOOLEAN,V_ASN1_UNIVERSAL); | 74 | ASN1_put_object(&p, 0, 1, V_ASN1_BOOLEAN, V_ASN1_UNIVERSAL); |
73 | *(p++)= (unsigned char)a; | 75 | *(p++) = (unsigned char)a; |
74 | *pp=p; | 76 | *pp = p; |
75 | return(r); | 77 | return (r); |
76 | } | 78 | } |
77 | 79 | ||
78 | int d2i_ASN1_BOOLEAN(int *a, const unsigned char **pp, long length) | 80 | int |
79 | { | 81 | d2i_ASN1_BOOLEAN(int *a, const unsigned char **pp, long length) |
80 | int ret= -1; | 82 | { |
83 | int ret = -1; | ||
81 | const unsigned char *p; | 84 | const unsigned char *p; |
82 | long len; | 85 | long len; |
83 | int inf,tag,xclass; | 86 | int inf, tag, xclass; |
84 | int i=0; | 87 | int i = 0; |
85 | 88 | ||
86 | p= *pp; | 89 | p = *pp; |
87 | inf=ASN1_get_object(&p,&len,&tag,&xclass,length); | 90 | inf = ASN1_get_object(&p, &len, &tag, &xclass, length); |
88 | if (inf & 0x80) | 91 | if (inf & 0x80) { |
89 | { | 92 | i = ASN1_R_BAD_OBJECT_HEADER; |
90 | i=ASN1_R_BAD_OBJECT_HEADER; | ||
91 | goto err; | 93 | goto err; |
92 | } | 94 | } |
93 | 95 | ||
94 | if (tag != V_ASN1_BOOLEAN) | 96 | if (tag != V_ASN1_BOOLEAN) { |
95 | { | 97 | i = ASN1_R_EXPECTING_A_BOOLEAN; |
96 | i=ASN1_R_EXPECTING_A_BOOLEAN; | ||
97 | goto err; | 98 | goto err; |
98 | } | 99 | } |
99 | 100 | ||
100 | if (len != 1) | 101 | if (len != 1) { |
101 | { | 102 | i = ASN1_R_BOOLEAN_IS_WRONG_LENGTH; |
102 | i=ASN1_R_BOOLEAN_IS_WRONG_LENGTH; | ||
103 | goto err; | 103 | goto err; |
104 | } | ||
105 | ret= (int)*(p++); | ||
106 | if (a != NULL) (*a)=ret; | ||
107 | *pp=p; | ||
108 | return(ret); | ||
109 | err: | ||
110 | ASN1err(ASN1_F_D2I_ASN1_BOOLEAN,i); | ||
111 | return(ret); | ||
112 | } | 104 | } |
105 | ret = (int)*(p++); | ||
106 | if (a != NULL) | ||
107 | (*a) = ret; | ||
108 | *pp = p; | ||
109 | return (ret); | ||
113 | 110 | ||
114 | 111 | err: | |
112 | ASN1err(ASN1_F_D2I_ASN1_BOOLEAN, i); | ||
113 | return (ret); | ||
114 | } | ||
diff --git a/src/lib/libssl/src/crypto/asn1/a_bytes.c b/src/lib/libssl/src/crypto/asn1/a_bytes.c index 8431d89edf..30647c97b5 100644 --- a/src/lib/libssl/src/crypto/asn1/a_bytes.c +++ b/src/lib/libssl/src/crypto/asn1/a_bytes.c | |||
@@ -5,21 +5,21 @@ | |||
5 | * This package is an SSL implementation written | 5 | * This package is an SSL implementation written |
6 | * by Eric Young (eay@cryptsoft.com). | 6 | * by Eric Young (eay@cryptsoft.com). |
7 | * The implementation was written so as to conform with Netscapes SSL. | 7 | * The implementation was written so as to conform with Netscapes SSL. |
8 | * | 8 | * |
9 | * This library is free for commercial and non-commercial use as long as | 9 | * This library is free for commercial and non-commercial use as long as |
10 | * the following conditions are aheared to. The following conditions | 10 | * the following conditions are aheared to. The following conditions |
11 | * apply to all code found in this distribution, be it the RC4, RSA, | 11 | * apply to all code found in this distribution, be it the RC4, RSA, |
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation |
13 | * included with this distribution is covered by the same copyright terms | 13 | * included with this distribution is covered by the same copyright terms |
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). |
15 | * | 15 | * |
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | 16 | * Copyright remains Eric Young's, and as such any Copyright notices in |
17 | * the code are not to be removed. | 17 | * the code are not to be removed. |
18 | * If this package is used in a product, Eric Young should be given attribution | 18 | * If this package is used in a product, Eric Young should be given attribution |
19 | * as the author of the parts of the library used. | 19 | * as the author of the parts of the library used. |
20 | * This can be in the form of a textual message at program startup or | 20 | * This can be in the form of a textual message at program startup or |
21 | * in documentation (online or textual) provided with the package. | 21 | * in documentation (online or textual) provided with the package. |
22 | * | 22 | * |
23 | * Redistribution and use in source and binary forms, with or without | 23 | * Redistribution and use in source and binary forms, with or without |
24 | * modification, are permitted provided that the following conditions | 24 | * modification, are permitted provided that the following conditions |
25 | * are met: | 25 | * are met: |
@@ -34,10 +34,10 @@ | |||
34 | * Eric Young (eay@cryptsoft.com)" | 34 | * Eric Young (eay@cryptsoft.com)" |
35 | * The word 'cryptographic' can be left out if the rouines from the library | 35 | * The word 'cryptographic' can be left out if the rouines from the library |
36 | * being used are not cryptographic related :-). | 36 | * being used are not cryptographic related :-). |
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | 37 | * 4. If you include any Windows specific code (or a derivative thereof) from |
38 | * the apps directory (application code) you must include an acknowledgement: | 38 | * the apps directory (application code) you must include an acknowledgement: |
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" |
40 | * | 40 | * |
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND |
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
@@ -49,7 +49,7 @@ | |||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
51 | * SUCH DAMAGE. | 51 | * SUCH DAMAGE. |
52 | * | 52 | * |
53 | * The licence and distribution terms for any publically available version or | 53 | * The licence and distribution terms for any publically available version or |
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be |
55 | * copied and put under another distribution licence | 55 | * copied and put under another distribution licence |
@@ -63,252 +63,247 @@ | |||
63 | static int asn1_collate_primitive(ASN1_STRING *a, ASN1_const_CTX *c); | 63 | static int asn1_collate_primitive(ASN1_STRING *a, ASN1_const_CTX *c); |
64 | /* type is a 'bitmap' of acceptable string types. | 64 | /* type is a 'bitmap' of acceptable string types. |
65 | */ | 65 | */ |
66 | ASN1_STRING *d2i_ASN1_type_bytes(ASN1_STRING **a, const unsigned char **pp, | 66 | ASN1_STRING * |
67 | long length, int type) | 67 | d2i_ASN1_type_bytes(ASN1_STRING **a, const unsigned char **pp, |
68 | { | 68 | long length, int type) |
69 | ASN1_STRING *ret=NULL; | 69 | { |
70 | ASN1_STRING *ret = NULL; | ||
70 | const unsigned char *p; | 71 | const unsigned char *p; |
71 | unsigned char *s; | 72 | unsigned char *s; |
72 | long len; | 73 | long len; |
73 | int inf,tag,xclass; | 74 | int inf, tag, xclass; |
74 | int i=0; | 75 | int i = 0; |
75 | 76 | ||
76 | p= *pp; | 77 | p = *pp; |
77 | inf=ASN1_get_object(&p,&len,&tag,&xclass,length); | 78 | inf = ASN1_get_object(&p, &len, &tag, &xclass, length); |
78 | if (inf & 0x80) goto err; | 79 | if (inf & 0x80) |
80 | goto err; | ||
79 | 81 | ||
80 | if (tag >= 32) | 82 | if (tag >= 32) { |
81 | { | 83 | i = ASN1_R_TAG_VALUE_TOO_HIGH; |
82 | i=ASN1_R_TAG_VALUE_TOO_HIGH; | ||
83 | goto err; | 84 | goto err; |
84 | } | 85 | } |
85 | if (!(ASN1_tag2bit(tag) & type)) | 86 | if (!(ASN1_tag2bit(tag) & type)) { |
86 | { | 87 | i = ASN1_R_WRONG_TYPE; |
87 | i=ASN1_R_WRONG_TYPE; | ||
88 | goto err; | 88 | goto err; |
89 | } | 89 | } |
90 | 90 | ||
91 | /* If a bit-string, exit early */ | 91 | /* If a bit-string, exit early */ |
92 | if (tag == V_ASN1_BIT_STRING) | 92 | if (tag == V_ASN1_BIT_STRING) |
93 | return(d2i_ASN1_BIT_STRING(a,pp,length)); | 93 | return (d2i_ASN1_BIT_STRING(a, pp, length)); |
94 | 94 | ||
95 | if ((a == NULL) || ((*a) == NULL)) | 95 | if ((a == NULL) || ((*a) == NULL)) { |
96 | { | 96 | if ((ret = ASN1_STRING_new()) == NULL) |
97 | if ((ret=ASN1_STRING_new()) == NULL) return(NULL); | 97 | return (NULL); |
98 | } | 98 | } else |
99 | else | 99 | ret = (*a); |
100 | ret=(*a); | 100 | |
101 | 101 | if (len != 0) { | |
102 | if (len != 0) | 102 | s = (unsigned char *)malloc((int)len + 1); |
103 | { | 103 | if (s == NULL) { |
104 | s=(unsigned char *)malloc((int)len+1); | 104 | i = ERR_R_MALLOC_FAILURE; |
105 | if (s == NULL) | ||
106 | { | ||
107 | i=ERR_R_MALLOC_FAILURE; | ||
108 | goto err; | 105 | goto err; |
109 | } | ||
110 | memcpy(s,p,(int)len); | ||
111 | s[len]='\0'; | ||
112 | p+=len; | ||
113 | } | 106 | } |
114 | else | 107 | memcpy(s, p, (int)len); |
115 | s=NULL; | 108 | s[len]='\0'; |
116 | 109 | p += len; | |
117 | if (ret->data != NULL) free(ret->data); | 110 | } else |
118 | ret->length=(int)len; | 111 | s = NULL; |
119 | ret->data=s; | 112 | |
120 | ret->type=tag; | 113 | if (ret->data != NULL) |
121 | if (a != NULL) (*a)=ret; | 114 | free(ret->data); |
122 | *pp=p; | 115 | ret->length = (int)len; |
123 | return(ret); | 116 | ret->data = s; |
117 | ret->type = tag; | ||
118 | if (a != NULL) | ||
119 | (*a) = ret; | ||
120 | *pp = p; | ||
121 | return (ret); | ||
122 | |||
124 | err: | 123 | err: |
125 | ASN1err(ASN1_F_D2I_ASN1_TYPE_BYTES,i); | 124 | ASN1err(ASN1_F_D2I_ASN1_TYPE_BYTES, i); |
126 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) | 125 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) |
127 | ASN1_STRING_free(ret); | 126 | ASN1_STRING_free(ret); |
128 | return(NULL); | 127 | return (NULL); |
129 | } | 128 | } |
130 | 129 | ||
131 | int i2d_ASN1_bytes(ASN1_STRING *a, unsigned char **pp, int tag, int xclass) | 130 | int |
132 | { | 131 | i2d_ASN1_bytes(ASN1_STRING *a, unsigned char **pp, int tag, int xclass) |
133 | int ret,r,constructed; | 132 | { |
133 | int ret, r, constructed; | ||
134 | unsigned char *p; | 134 | unsigned char *p; |
135 | 135 | ||
136 | if (a == NULL) return(0); | 136 | if (a == NULL) |
137 | return (0); | ||
137 | 138 | ||
138 | if (tag == V_ASN1_BIT_STRING) | 139 | if (tag == V_ASN1_BIT_STRING) |
139 | return(i2d_ASN1_BIT_STRING(a,pp)); | 140 | return (i2d_ASN1_BIT_STRING(a, pp)); |
140 | 141 | ||
141 | ret=a->length; | 142 | ret = a->length; |
142 | r=ASN1_object_size(0,ret,tag); | 143 | r = ASN1_object_size(0, ret, tag); |
143 | if (pp == NULL) return(r); | 144 | if (pp == NULL) |
144 | p= *pp; | 145 | return (r); |
146 | p = *pp; | ||
145 | 147 | ||
146 | if ((tag == V_ASN1_SEQUENCE) || (tag == V_ASN1_SET)) | 148 | if ((tag == V_ASN1_SEQUENCE) || (tag == V_ASN1_SET)) |
147 | constructed=1; | 149 | constructed = 1; |
148 | else | 150 | else |
149 | constructed=0; | 151 | constructed = 0; |
150 | ASN1_put_object(&p,constructed,ret,tag,xclass); | 152 | ASN1_put_object(&p, constructed, ret, tag, xclass); |
151 | memcpy(p,a->data,a->length); | 153 | memcpy(p, a->data, a->length); |
152 | p+=a->length; | 154 | p += a->length; |
153 | *pp= p; | 155 | *pp = p; |
154 | return(r); | 156 | return (r); |
155 | } | 157 | } |
156 | 158 | ||
157 | ASN1_STRING *d2i_ASN1_bytes(ASN1_STRING **a, const unsigned char **pp, | 159 | ASN1_STRING * |
158 | long length, int Ptag, int Pclass) | 160 | d2i_ASN1_bytes(ASN1_STRING **a, const unsigned char **pp, |
159 | { | 161 | long length, int Ptag, int Pclass) |
160 | ASN1_STRING *ret=NULL; | 162 | { |
163 | ASN1_STRING *ret = NULL; | ||
161 | const unsigned char *p; | 164 | const unsigned char *p; |
162 | unsigned char *s; | 165 | unsigned char *s; |
163 | long len; | 166 | long len; |
164 | int inf,tag,xclass; | 167 | int inf, tag, xclass; |
165 | int i=0; | 168 | int i = 0; |
166 | 169 | ||
167 | if ((a == NULL) || ((*a) == NULL)) | 170 | if ((a == NULL) || ((*a) == NULL)) { |
168 | { | 171 | if ((ret = ASN1_STRING_new()) == NULL) |
169 | if ((ret=ASN1_STRING_new()) == NULL) return(NULL); | 172 | return (NULL); |
170 | } | 173 | } else |
171 | else | 174 | ret = (*a); |
172 | ret=(*a); | ||
173 | 175 | ||
174 | p= *pp; | 176 | p= *pp; |
175 | inf=ASN1_get_object(&p,&len,&tag,&xclass,length); | 177 | inf = ASN1_get_object(&p, &len, &tag, &xclass, length); |
176 | if (inf & 0x80) | 178 | if (inf & 0x80) { |
177 | { | 179 | i = ASN1_R_BAD_OBJECT_HEADER; |
178 | i=ASN1_R_BAD_OBJECT_HEADER; | ||
179 | goto err; | 180 | goto err; |
180 | } | 181 | } |
181 | 182 | ||
182 | if (tag != Ptag) | 183 | if (tag != Ptag) { |
183 | { | 184 | i = ASN1_R_WRONG_TAG; |
184 | i=ASN1_R_WRONG_TAG; | ||
185 | goto err; | 185 | goto err; |
186 | } | 186 | } |
187 | 187 | ||
188 | if (inf & V_ASN1_CONSTRUCTED) | 188 | if (inf & V_ASN1_CONSTRUCTED) { |
189 | { | ||
190 | ASN1_const_CTX c; | 189 | ASN1_const_CTX c; |
191 | 190 | ||
192 | c.pp=pp; | 191 | c.pp = pp; |
193 | c.p=p; | 192 | c.p = p; |
194 | c.inf=inf; | 193 | c.inf = inf; |
195 | c.slen=len; | 194 | c.slen = len; |
196 | c.tag=Ptag; | 195 | c.tag = Ptag; |
197 | c.xclass=Pclass; | 196 | c.xclass = Pclass; |
198 | c.max=(length == 0)?0:(p+length); | 197 | c.max = (length == 0) ? 0 : (p + length); |
199 | if (!asn1_collate_primitive(ret,&c)) | 198 | if (!asn1_collate_primitive(ret, &c)) |
200 | goto err; | 199 | goto err; |
201 | else | 200 | else { |
202 | { | 201 | p = c.p; |
203 | p=c.p; | ||
204 | } | ||
205 | } | 202 | } |
206 | else | 203 | } else { |
207 | { | 204 | if (len != 0) { |
208 | if (len != 0) | 205 | if ((ret->length < len) || (ret->data == NULL)) { |
209 | { | 206 | if (ret->data != NULL) |
210 | if ((ret->length < len) || (ret->data == NULL)) | 207 | free(ret->data); |
211 | { | 208 | s = (unsigned char *)malloc((int)len + 1); |
212 | if (ret->data != NULL) free(ret->data); | 209 | if (s == NULL) { |
213 | s=(unsigned char *)malloc((int)len + 1); | 210 | i = ERR_R_MALLOC_FAILURE; |
214 | if (s == NULL) | ||
215 | { | ||
216 | i=ERR_R_MALLOC_FAILURE; | ||
217 | goto err; | 211 | goto err; |
218 | } | ||
219 | } | 212 | } |
220 | else | 213 | } else |
221 | s=ret->data; | 214 | s = ret->data; |
222 | memcpy(s,p,(int)len); | 215 | memcpy(s, p, (int)len); |
223 | s[len] = '\0'; | 216 | s[len] = '\0'; |
224 | p+=len; | 217 | p += len; |
225 | } | 218 | } else { |
226 | else | 219 | s = NULL; |
227 | { | 220 | if (ret->data != NULL) |
228 | s=NULL; | 221 | free(ret->data); |
229 | if (ret->data != NULL) free(ret->data); | ||
230 | } | ||
231 | |||
232 | ret->length=(int)len; | ||
233 | ret->data=s; | ||
234 | ret->type=Ptag; | ||
235 | } | 222 | } |
236 | 223 | ||
237 | if (a != NULL) (*a)=ret; | 224 | ret->length = (int)len; |
238 | *pp=p; | 225 | ret->data = s; |
239 | return(ret); | 226 | ret->type = Ptag; |
227 | } | ||
228 | |||
229 | if (a != NULL) | ||
230 | (*a) = ret; | ||
231 | *pp = p; | ||
232 | return (ret); | ||
233 | |||
240 | err: | 234 | err: |
241 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) | 235 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) |
242 | ASN1_STRING_free(ret); | 236 | ASN1_STRING_free(ret); |
243 | ASN1err(ASN1_F_D2I_ASN1_BYTES,i); | 237 | ASN1err(ASN1_F_D2I_ASN1_BYTES, i); |
244 | return(NULL); | 238 | return (NULL); |
245 | } | 239 | } |
246 | 240 | ||
247 | 241 | ||
248 | /* We are about to parse 0..n d2i_ASN1_bytes objects, we are to collapse | 242 | /* We are about to parse 0..n d2i_ASN1_bytes objects, we are to collapse |
249 | * them into the one structure that is then returned */ | 243 | * them into the one structure that is then returned */ |
250 | /* There have been a few bug fixes for this function from | 244 | /* There have been a few bug fixes for this function from |
251 | * Paul Keogh <paul.keogh@sse.ie>, many thanks to him */ | 245 | * Paul Keogh <paul.keogh@sse.ie>, many thanks to him */ |
252 | static int asn1_collate_primitive(ASN1_STRING *a, ASN1_const_CTX *c) | 246 | static int |
253 | { | 247 | asn1_collate_primitive(ASN1_STRING *a, ASN1_const_CTX *c) |
254 | ASN1_STRING *os=NULL; | 248 | { |
249 | ASN1_STRING *os = NULL; | ||
255 | BUF_MEM b; | 250 | BUF_MEM b; |
256 | int num; | 251 | int num; |
257 | 252 | ||
258 | b.length=0; | 253 | b.length = 0; |
259 | b.max=0; | 254 | b.max = 0; |
260 | b.data=NULL; | 255 | b.data = NULL; |
261 | 256 | ||
262 | if (a == NULL) | 257 | if (a == NULL) { |
263 | { | 258 | c->error = ERR_R_PASSED_NULL_PARAMETER; |
264 | c->error=ERR_R_PASSED_NULL_PARAMETER; | ||
265 | goto err; | 259 | goto err; |
260 | } | ||
261 | |||
262 | num = 0; | ||
263 | for (;;) { | ||
264 | if (c->inf & 1) { | ||
265 | c->eos = ASN1_const_check_infinite_end(&c->p, | ||
266 | (long)(c->max - c->p)); | ||
267 | if (c->eos) | ||
268 | break; | ||
269 | } else { | ||
270 | if (c->slen <= 0) | ||
271 | break; | ||
266 | } | 272 | } |
267 | 273 | ||
268 | num=0; | 274 | c->q = c->p; |
269 | for (;;) | 275 | if (d2i_ASN1_bytes(&os, &c->p, c->max - c->p, c->tag, |
270 | { | 276 | c->xclass) == NULL) { |
271 | if (c->inf & 1) | 277 | c->error = ERR_R_ASN1_LIB; |
272 | { | ||
273 | c->eos=ASN1_const_check_infinite_end(&c->p, | ||
274 | (long)(c->max-c->p)); | ||
275 | if (c->eos) break; | ||
276 | } | ||
277 | else | ||
278 | { | ||
279 | if (c->slen <= 0) break; | ||
280 | } | ||
281 | |||
282 | c->q=c->p; | ||
283 | if (d2i_ASN1_bytes(&os,&c->p,c->max-c->p,c->tag,c->xclass) | ||
284 | == NULL) | ||
285 | { | ||
286 | c->error=ERR_R_ASN1_LIB; | ||
287 | goto err; | 278 | goto err; |
288 | } | 279 | } |
289 | 280 | ||
290 | if (!BUF_MEM_grow_clean(&b,num+os->length)) | 281 | if (!BUF_MEM_grow_clean(&b, num + os->length)) { |
291 | { | 282 | c->error = ERR_R_BUF_LIB; |
292 | c->error=ERR_R_BUF_LIB; | ||
293 | goto err; | 283 | goto err; |
294 | } | ||
295 | memcpy(&(b.data[num]),os->data,os->length); | ||
296 | if (!(c->inf & 1)) | ||
297 | c->slen-=(c->p-c->q); | ||
298 | num+=os->length; | ||
299 | } | 284 | } |
285 | memcpy(&(b.data[num]), os->data, os->length); | ||
286 | if (!(c->inf & 1)) | ||
287 | c->slen -= (c->p - c->q); | ||
288 | num += os->length; | ||
289 | } | ||
290 | |||
291 | if (!asn1_const_Finish(c)) | ||
292 | goto err; | ||
300 | 293 | ||
301 | if (!asn1_const_Finish(c)) goto err; | 294 | a->length = num; |
295 | if (a->data != NULL) | ||
296 | free(a->data); | ||
297 | a->data = (unsigned char *)b.data; | ||
298 | if (os != NULL) | ||
299 | ASN1_STRING_free(os); | ||
300 | return (1); | ||
302 | 301 | ||
303 | a->length=num; | ||
304 | if (a->data != NULL) free(a->data); | ||
305 | a->data=(unsigned char *)b.data; | ||
306 | if (os != NULL) ASN1_STRING_free(os); | ||
307 | return(1); | ||
308 | err: | 302 | err: |
309 | ASN1err(ASN1_F_ASN1_COLLATE_PRIMITIVE,c->error); | 303 | ASN1err(ASN1_F_ASN1_COLLATE_PRIMITIVE, c->error); |
310 | if (os != NULL) ASN1_STRING_free(os); | 304 | if (os != NULL) |
311 | if (b.data != NULL) free(b.data); | 305 | ASN1_STRING_free(os); |
312 | return(0); | 306 | if (b.data != NULL) |
313 | } | 307 | free(b.data); |
314 | 308 | return (0); | |
309 | } | ||
diff --git a/src/lib/libssl/src/crypto/asn1/a_d2i_fp.c b/src/lib/libssl/src/crypto/asn1/a_d2i_fp.c index 52b2ebdb63..af7a4bac30 100644 --- a/src/lib/libssl/src/crypto/asn1/a_d2i_fp.c +++ b/src/lib/libssl/src/crypto/asn1/a_d2i_fp.c | |||
@@ -5,21 +5,21 @@ | |||
5 | * This package is an SSL implementation written | 5 | * This package is an SSL implementation written |
6 | * by Eric Young (eay@cryptsoft.com). | 6 | * by Eric Young (eay@cryptsoft.com). |
7 | * The implementation was written so as to conform with Netscapes SSL. | 7 | * The implementation was written so as to conform with Netscapes SSL. |
8 | * | 8 | * |
9 | * This library is free for commercial and non-commercial use as long as | 9 | * This library is free for commercial and non-commercial use as long as |
10 | * the following conditions are aheared to. The following conditions | 10 | * the following conditions are aheared to. The following conditions |
11 | * apply to all code found in this distribution, be it the RC4, RSA, | 11 | * apply to all code found in this distribution, be it the RC4, RSA, |
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation |
13 | * included with this distribution is covered by the same copyright terms | 13 | * included with this distribution is covered by the same copyright terms |
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). |
15 | * | 15 | * |
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | 16 | * Copyright remains Eric Young's, and as such any Copyright notices in |
17 | * the code are not to be removed. | 17 | * the code are not to be removed. |
18 | * If this package is used in a product, Eric Young should be given attribution | 18 | * If this package is used in a product, Eric Young should be given attribution |
19 | * as the author of the parts of the library used. | 19 | * as the author of the parts of the library used. |
20 | * This can be in the form of a textual message at program startup or | 20 | * This can be in the form of a textual message at program startup or |
21 | * in documentation (online or textual) provided with the package. | 21 | * in documentation (online or textual) provided with the package. |
22 | * | 22 | * |
23 | * Redistribution and use in source and binary forms, with or without | 23 | * Redistribution and use in source and binary forms, with or without |
24 | * modification, are permitted provided that the following conditions | 24 | * modification, are permitted provided that the following conditions |
25 | * are met: | 25 | * are met: |
@@ -34,10 +34,10 @@ | |||
34 | * Eric Young (eay@cryptsoft.com)" | 34 | * Eric Young (eay@cryptsoft.com)" |
35 | * The word 'cryptographic' can be left out if the rouines from the library | 35 | * The word 'cryptographic' can be left out if the rouines from the library |
36 | * being used are not cryptographic related :-). | 36 | * being used are not cryptographic related :-). |
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | 37 | * 4. If you include any Windows specific code (or a derivative thereof) from |
38 | * the apps directory (application code) you must include an acknowledgement: | 38 | * the apps directory (application code) you must include an acknowledgement: |
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" |
40 | * | 40 | * |
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND |
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
@@ -49,7 +49,7 @@ | |||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
51 | * SUCH DAMAGE. | 51 | * SUCH DAMAGE. |
52 | * | 52 | * |
53 | * The licence and distribution terms for any publically available version or | 53 | * The licence and distribution terms for any publically available version or |
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be |
55 | * copied and put under another distribution licence | 55 | * copied and put under another distribution licence |
@@ -67,220 +67,208 @@ static int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb); | |||
67 | #ifndef NO_OLD_ASN1 | 67 | #ifndef NO_OLD_ASN1 |
68 | #ifndef OPENSSL_NO_FP_API | 68 | #ifndef OPENSSL_NO_FP_API |
69 | 69 | ||
70 | void *ASN1_d2i_fp(void *(*xnew)(void), d2i_of_void *d2i, FILE *in, void **x) | 70 | void * |
71 | { | 71 | ASN1_d2i_fp(void *(*xnew)(void), d2i_of_void *d2i, FILE *in, void **x) |
72 | BIO *b; | 72 | { |
73 | void *ret; | 73 | BIO *b; |
74 | void *ret; | ||
74 | 75 | ||
75 | if ((b=BIO_new(BIO_s_file())) == NULL) | 76 | if ((b = BIO_new(BIO_s_file())) == NULL) { |
76 | { | 77 | ASN1err(ASN1_F_ASN1_D2I_FP, ERR_R_BUF_LIB); |
77 | ASN1err(ASN1_F_ASN1_D2I_FP,ERR_R_BUF_LIB); | 78 | return (NULL); |
78 | return(NULL); | 79 | } |
79 | } | 80 | BIO_set_fp(b, in, BIO_NOCLOSE); |
80 | BIO_set_fp(b,in,BIO_NOCLOSE); | 81 | ret = ASN1_d2i_bio(xnew, d2i, b, x); |
81 | ret=ASN1_d2i_bio(xnew,d2i,b,x); | 82 | BIO_free(b); |
82 | BIO_free(b); | 83 | return (ret); |
83 | return(ret); | 84 | } |
84 | } | ||
85 | #endif | 85 | #endif |
86 | 86 | ||
87 | void *ASN1_d2i_bio(void *(*xnew)(void), d2i_of_void *d2i, BIO *in, void **x) | 87 | void * |
88 | { | 88 | ASN1_d2i_bio(void *(*xnew)(void), d2i_of_void *d2i, BIO *in, void **x) |
89 | { | ||
89 | BUF_MEM *b = NULL; | 90 | BUF_MEM *b = NULL; |
90 | const unsigned char *p; | 91 | const unsigned char *p; |
91 | void *ret=NULL; | 92 | void *ret = NULL; |
92 | int len; | 93 | int len; |
93 | 94 | ||
94 | len = asn1_d2i_read_bio(in, &b); | 95 | len = asn1_d2i_read_bio(in, &b); |
95 | if(len < 0) goto err; | 96 | if (len < 0) |
97 | goto err; | ||
98 | |||
99 | p = (unsigned char *)b->data; | ||
100 | ret = d2i(x, &p, len); | ||
96 | 101 | ||
97 | p=(unsigned char *)b->data; | ||
98 | ret=d2i(x,&p,len); | ||
99 | err: | 102 | err: |
100 | if (b != NULL) BUF_MEM_free(b); | 103 | if (b != NULL) |
101 | return(ret); | 104 | BUF_MEM_free(b); |
102 | } | 105 | return (ret); |
106 | } | ||
103 | 107 | ||
104 | #endif | 108 | #endif |
105 | 109 | ||
106 | void *ASN1_item_d2i_bio(const ASN1_ITEM *it, BIO *in, void *x) | 110 | void * |
107 | { | 111 | ASN1_item_d2i_bio(const ASN1_ITEM *it, BIO *in, void *x) |
112 | { | ||
108 | BUF_MEM *b = NULL; | 113 | BUF_MEM *b = NULL; |
109 | const unsigned char *p; | 114 | const unsigned char *p; |
110 | void *ret=NULL; | 115 | void *ret = NULL; |
111 | int len; | 116 | int len; |
112 | 117 | ||
113 | len = asn1_d2i_read_bio(in, &b); | 118 | len = asn1_d2i_read_bio(in, &b); |
114 | if(len < 0) goto err; | 119 | if (len < 0) |
120 | goto err; | ||
121 | |||
122 | p = (const unsigned char *)b->data; | ||
123 | ret = ASN1_item_d2i(x, &p, len, it); | ||
115 | 124 | ||
116 | p=(const unsigned char *)b->data; | ||
117 | ret=ASN1_item_d2i(x,&p,len, it); | ||
118 | err: | 125 | err: |
119 | if (b != NULL) BUF_MEM_free(b); | 126 | if (b != NULL) |
120 | return(ret); | 127 | BUF_MEM_free(b); |
121 | } | 128 | return (ret); |
129 | } | ||
122 | 130 | ||
123 | #ifndef OPENSSL_NO_FP_API | 131 | #ifndef OPENSSL_NO_FP_API |
124 | void *ASN1_item_d2i_fp(const ASN1_ITEM *it, FILE *in, void *x) | 132 | void * |
125 | { | 133 | ASN1_item_d2i_fp(const ASN1_ITEM *it, FILE *in, void *x) |
126 | BIO *b; | 134 | { |
127 | char *ret; | 135 | BIO *b; |
136 | char *ret; | ||
128 | 137 | ||
129 | if ((b=BIO_new(BIO_s_file())) == NULL) | 138 | if ((b = BIO_new(BIO_s_file())) == NULL) { |
130 | { | 139 | ASN1err(ASN1_F_ASN1_ITEM_D2I_FP, ERR_R_BUF_LIB); |
131 | ASN1err(ASN1_F_ASN1_ITEM_D2I_FP,ERR_R_BUF_LIB); | 140 | return (NULL); |
132 | return(NULL); | 141 | } |
133 | } | 142 | BIO_set_fp(b, in, BIO_NOCLOSE); |
134 | BIO_set_fp(b,in,BIO_NOCLOSE); | 143 | ret = ASN1_item_d2i_bio(it, b, x); |
135 | ret=ASN1_item_d2i_bio(it,b,x); | 144 | BIO_free(b); |
136 | BIO_free(b); | 145 | return (ret); |
137 | return(ret); | 146 | } |
138 | } | ||
139 | #endif | 147 | #endif |
140 | 148 | ||
141 | #define HEADER_SIZE 8 | 149 | #define HEADER_SIZE 8 |
142 | static int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb) | 150 | static int |
143 | { | 151 | asn1_d2i_read_bio(BIO *in, BUF_MEM **pb) |
152 | { | ||
144 | BUF_MEM *b; | 153 | BUF_MEM *b; |
145 | unsigned char *p; | 154 | unsigned char *p; |
146 | int i; | 155 | int i; |
147 | ASN1_const_CTX c; | 156 | ASN1_const_CTX c; |
148 | size_t want=HEADER_SIZE; | 157 | size_t want = HEADER_SIZE; |
149 | int eos=0; | 158 | int eos = 0; |
150 | size_t off=0; | 159 | size_t off = 0; |
151 | size_t len=0; | 160 | size_t len = 0; |
152 | 161 | ||
153 | b=BUF_MEM_new(); | 162 | b = BUF_MEM_new(); |
154 | if (b == NULL) | 163 | if (b == NULL) { |
155 | { | 164 | ASN1err(ASN1_F_ASN1_D2I_READ_BIO, ERR_R_MALLOC_FAILURE); |
156 | ASN1err(ASN1_F_ASN1_D2I_READ_BIO,ERR_R_MALLOC_FAILURE); | ||
157 | return -1; | 165 | return -1; |
158 | } | 166 | } |
159 | 167 | ||
160 | ERR_clear_error(); | 168 | ERR_clear_error(); |
161 | for (;;) | 169 | for (;;) { |
162 | { | 170 | if (want >= (len - off)) { |
163 | if (want >= (len-off)) | 171 | want -= (len - off); |
164 | { | ||
165 | want-=(len-off); | ||
166 | 172 | ||
167 | if (len + want < len || !BUF_MEM_grow_clean(b,len+want)) | 173 | if (len + want < len || !BUF_MEM_grow_clean(b, len + want)) { |
168 | { | 174 | ASN1err(ASN1_F_ASN1_D2I_READ_BIO, ERR_R_MALLOC_FAILURE); |
169 | ASN1err(ASN1_F_ASN1_D2I_READ_BIO,ERR_R_MALLOC_FAILURE); | ||
170 | goto err; | 175 | goto err; |
171 | } | 176 | } |
172 | i=BIO_read(in,&(b->data[len]),want); | 177 | i = BIO_read(in, &(b->data[len]), want); |
173 | if ((i < 0) && ((len-off) == 0)) | 178 | if ((i < 0) && ((len - off) == 0)) { |
174 | { | 179 | ASN1err(ASN1_F_ASN1_D2I_READ_BIO, ASN1_R_NOT_ENOUGH_DATA); |
175 | ASN1err(ASN1_F_ASN1_D2I_READ_BIO,ASN1_R_NOT_ENOUGH_DATA); | ||
176 | goto err; | 180 | goto err; |
177 | } | 181 | } |
178 | if (i > 0) | 182 | if (i > 0) { |
179 | { | 183 | if (len + i < len) { |
180 | if (len+i < len) | 184 | ASN1err(ASN1_F_ASN1_D2I_READ_BIO, ASN1_R_TOO_LONG); |
181 | { | ||
182 | ASN1err(ASN1_F_ASN1_D2I_READ_BIO,ASN1_R_TOO_LONG); | ||
183 | goto err; | 185 | goto err; |
184 | } | ||
185 | len+=i; | ||
186 | } | 186 | } |
187 | len += i; | ||
187 | } | 188 | } |
189 | } | ||
188 | /* else data already loaded */ | 190 | /* else data already loaded */ |
189 | 191 | ||
190 | p=(unsigned char *)&(b->data[off]); | 192 | p = (unsigned char *) & (b->data[off]); |
191 | c.p=p; | 193 | c.p = p; |
192 | c.inf=ASN1_get_object(&(c.p),&(c.slen),&(c.tag),&(c.xclass), | 194 | c.inf = ASN1_get_object(&(c.p), &(c.slen), &(c.tag), |
193 | len-off); | 195 | &(c.xclass), len - off); |
194 | if (c.inf & 0x80) | 196 | if (c.inf & 0x80) { |
195 | { | ||
196 | unsigned long e; | 197 | unsigned long e; |
197 | 198 | ||
198 | e=ERR_GET_REASON(ERR_peek_error()); | 199 | e = ERR_GET_REASON(ERR_peek_error()); |
199 | if (e != ASN1_R_TOO_LONG) | 200 | if (e != ASN1_R_TOO_LONG) |
200 | goto err; | 201 | goto err; |
201 | else | 202 | else |
202 | ERR_clear_error(); /* clear error */ | 203 | ERR_clear_error(); /* clear error */ |
203 | } | 204 | } |
204 | i=c.p-p;/* header length */ | 205 | i = c.p - p; /* header length */ |
205 | off+=i; /* end of data */ | 206 | off += i; /* end of data */ |
206 | 207 | ||
207 | if (c.inf & 1) | 208 | if (c.inf & 1) { |
208 | { | ||
209 | /* no data body so go round again */ | 209 | /* no data body so go round again */ |
210 | eos++; | 210 | eos++; |
211 | if (eos < 0) | 211 | if (eos < 0) { |
212 | { | 212 | ASN1err(ASN1_F_ASN1_D2I_READ_BIO, ASN1_R_HEADER_TOO_LONG); |
213 | ASN1err(ASN1_F_ASN1_D2I_READ_BIO,ASN1_R_HEADER_TOO_LONG); | ||
214 | goto err; | 213 | goto err; |
215 | } | ||
216 | want=HEADER_SIZE; | ||
217 | } | 214 | } |
218 | else if (eos && (c.slen == 0) && (c.tag == V_ASN1_EOC)) | 215 | want = HEADER_SIZE; |
219 | { | 216 | } else if (eos && (c.slen == 0) && (c.tag == V_ASN1_EOC)) { |
220 | /* eos value, so go back and read another header */ | 217 | /* eos value, so go back and read another header */ |
221 | eos--; | 218 | eos--; |
222 | if (eos <= 0) | 219 | if (eos <= 0) |
223 | break; | 220 | break; |
224 | else | 221 | else |
225 | want=HEADER_SIZE; | 222 | want = HEADER_SIZE; |
226 | } | 223 | } else { |
227 | else | ||
228 | { | ||
229 | /* suck in c.slen bytes of data */ | 224 | /* suck in c.slen bytes of data */ |
230 | want=c.slen; | 225 | want = c.slen; |
231 | if (want > (len-off)) | 226 | if (want > (len - off)) { |
232 | { | 227 | want -= (len - off); |
233 | want-=(len-off); | ||
234 | if (want > INT_MAX /* BIO_read takes an int length */ || | 228 | if (want > INT_MAX /* BIO_read takes an int length */ || |
235 | len+want < len) | 229 | len+want < len) { |
236 | { | 230 | ASN1err(ASN1_F_ASN1_D2I_READ_BIO, ASN1_R_TOO_LONG); |
237 | ASN1err(ASN1_F_ASN1_D2I_READ_BIO,ASN1_R_TOO_LONG); | ||
238 | goto err; | ||
239 | } | ||
240 | if (!BUF_MEM_grow_clean(b,len+want)) | ||
241 | { | ||
242 | ASN1err(ASN1_F_ASN1_D2I_READ_BIO,ERR_R_MALLOC_FAILURE); | ||
243 | goto err; | 231 | goto err; |
244 | } | 232 | } |
245 | while (want > 0) | 233 | if (!BUF_MEM_grow_clean(b, len + want)) { |
246 | { | 234 | ASN1err(ASN1_F_ASN1_D2I_READ_BIO, ERR_R_MALLOC_FAILURE); |
247 | i=BIO_read(in,&(b->data[len]),want); | 235 | goto err; |
248 | if (i <= 0) | 236 | } |
249 | { | 237 | while (want > 0) { |
238 | i = BIO_read(in, &(b->data[len]), want); | ||
239 | if (i <= 0) { | ||
250 | ASN1err(ASN1_F_ASN1_D2I_READ_BIO, | 240 | ASN1err(ASN1_F_ASN1_D2I_READ_BIO, |
251 | ASN1_R_NOT_ENOUGH_DATA); | 241 | ASN1_R_NOT_ENOUGH_DATA); |
252 | goto err; | 242 | goto err; |
253 | } | 243 | } |
254 | /* This can't overflow because | 244 | /* This can't overflow because |
255 | * |len+want| didn't overflow. */ | 245 | * |len+want| didn't overflow. */ |
256 | len+=i; | 246 | len += i; |
257 | want-=i; | 247 | want -= i; |
258 | } | ||
259 | } | 248 | } |
260 | if (off + c.slen < off) | 249 | } |
261 | { | 250 | if (off + c.slen < off) { |
262 | ASN1err(ASN1_F_ASN1_D2I_READ_BIO,ASN1_R_TOO_LONG); | 251 | ASN1err(ASN1_F_ASN1_D2I_READ_BIO, ASN1_R_TOO_LONG); |
263 | goto err; | 252 | goto err; |
264 | } | ||
265 | off+=c.slen; | ||
266 | if (eos <= 0) | ||
267 | { | ||
268 | break; | ||
269 | } | ||
270 | else | ||
271 | want=HEADER_SIZE; | ||
272 | } | 253 | } |
254 | off += c.slen; | ||
255 | if (eos <= 0) { | ||
256 | break; | ||
257 | } else | ||
258 | want = HEADER_SIZE; | ||
273 | } | 259 | } |
260 | } | ||
274 | 261 | ||
275 | if (off > INT_MAX) | 262 | if (off > INT_MAX) { |
276 | { | 263 | ASN1err(ASN1_F_ASN1_D2I_READ_BIO, ASN1_R_TOO_LONG); |
277 | ASN1err(ASN1_F_ASN1_D2I_READ_BIO,ASN1_R_TOO_LONG); | ||
278 | goto err; | 264 | goto err; |
279 | } | 265 | } |
280 | 266 | ||
281 | *pb = b; | 267 | *pb = b; |
282 | return off; | 268 | return off; |
269 | |||
283 | err: | 270 | err: |
284 | if (b != NULL) BUF_MEM_free(b); | 271 | if (b != NULL) |
272 | BUF_MEM_free(b); | ||
285 | return -1; | 273 | return -1; |
286 | } | 274 | } |