diff options
-rw-r--r-- | src/lib/libcrypto/stack/stack.c | 379 | ||||
-rw-r--r-- | src/lib/libcrypto/stack/stack.h | 21 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/stack/stack.c | 379 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/stack/stack.h | 21 |
4 files changed, 438 insertions, 362 deletions
diff --git a/src/lib/libcrypto/stack/stack.c b/src/lib/libcrypto/stack/stack.c index dabf26d2cd..a409a7e967 100644 --- a/src/lib/libcrypto/stack/stack.c +++ b/src/lib/libcrypto/stack/stack.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 |
@@ -77,258 +77,297 @@ const char STACK_version[]="Stack" OPENSSL_VERSION_PTEXT; | |||
77 | 77 | ||
78 | #include <errno.h> | 78 | #include <errno.h> |
79 | 79 | ||
80 | int (*sk_set_cmp_func(_STACK *sk, int (*c)(const void *, const void *))) | 80 | int |
81 | (const void *, const void *) | 81 | (*sk_set_cmp_func(_STACK *sk, int (*c)(const void *, const void *)))( |
82 | { | 82 | const void *, const void *) |
83 | int (*old)(const void *,const void *)=sk->comp; | 83 | { |
84 | int (*old)(const void *, const void *) = sk->comp; | ||
84 | 85 | ||
85 | if (sk->comp != c) | 86 | if (sk->comp != c) |
86 | sk->sorted=0; | 87 | sk->sorted = 0; |
87 | sk->comp=c; | 88 | sk->comp = c; |
88 | 89 | ||
89 | return old; | 90 | return old; |
90 | } | 91 | } |
91 | 92 | ||
92 | _STACK *sk_dup(_STACK *sk) | 93 | _STACK * |
93 | { | 94 | sk_dup(_STACK *sk) |
95 | { | ||
94 | _STACK *ret; | 96 | _STACK *ret; |
95 | char **s; | 97 | char **s; |
96 | 98 | ||
97 | if ((ret=sk_new(sk->comp)) == NULL) goto err; | 99 | if ((ret = sk_new(sk->comp)) == NULL) |
98 | s=(char **)realloc((char *)ret->data, | 100 | goto err; |
99 | (unsigned int)sizeof(char *)*sk->num_alloc); | 101 | s = (char **)realloc((char *)ret->data, |
100 | if (s == NULL) goto err; | 102 | (unsigned int)sizeof(char *) * sk->num_alloc); |
101 | ret->data=s; | 103 | if (s == NULL) |
102 | 104 | goto err; | |
103 | ret->num=sk->num; | 105 | ret->data = s; |
104 | memcpy(ret->data,sk->data,sizeof(char *)*sk->num); | 106 | |
105 | ret->sorted=sk->sorted; | 107 | ret->num = sk->num; |
106 | ret->num_alloc=sk->num_alloc; | 108 | memcpy(ret->data, sk->data, sizeof(char *) * sk->num); |
107 | ret->comp=sk->comp; | 109 | ret->sorted = sk->sorted; |
108 | return(ret); | 110 | ret->num_alloc = sk->num_alloc; |
111 | ret->comp = sk->comp; | ||
112 | return (ret); | ||
113 | |||
109 | err: | 114 | err: |
110 | if(ret) | 115 | if (ret) |
111 | sk_free(ret); | 116 | sk_free(ret); |
112 | return(NULL); | 117 | return (NULL); |
113 | } | 118 | } |
114 | 119 | ||
115 | _STACK *sk_new_null(void) | 120 | _STACK * |
116 | { | 121 | sk_new_null(void) |
122 | { | ||
117 | return sk_new((int (*)(const void *, const void *))0); | 123 | return sk_new((int (*)(const void *, const void *))0); |
118 | } | 124 | } |
119 | 125 | ||
120 | _STACK *sk_new(int (*c)(const void *, const void *)) | 126 | _STACK * |
121 | { | 127 | sk_new(int (*c)(const void *, const void *)) |
128 | { | ||
122 | _STACK *ret; | 129 | _STACK *ret; |
123 | int i; | 130 | int i; |
124 | 131 | ||
125 | if ((ret=malloc(sizeof(_STACK))) == NULL) | 132 | if ((ret = malloc(sizeof(_STACK))) == NULL) |
126 | goto err; | 133 | goto err; |
127 | if ((ret->data=malloc(sizeof(char *)*MIN_NODES)) == NULL) | 134 | if ((ret->data = malloc(sizeof(char *) * MIN_NODES)) == NULL) |
128 | goto err; | 135 | goto err; |
129 | for (i=0; i<MIN_NODES; i++) | 136 | for (i = 0; i < MIN_NODES; i++) |
130 | ret->data[i]=NULL; | 137 | ret->data[i] = NULL; |
131 | ret->comp=c; | 138 | ret->comp = c; |
132 | ret->num_alloc=MIN_NODES; | 139 | ret->num_alloc = MIN_NODES; |
133 | ret->num=0; | 140 | ret->num = 0; |
134 | ret->sorted=0; | 141 | ret->sorted = 0; |
135 | return(ret); | 142 | return (ret); |
143 | |||
136 | err: | 144 | err: |
137 | if(ret) | 145 | if (ret) |
138 | free(ret); | 146 | free(ret); |
139 | return(NULL); | 147 | return (NULL); |
140 | } | 148 | } |
141 | 149 | ||
142 | int sk_insert(_STACK *st, void *data, int loc) | 150 | int |
143 | { | 151 | sk_insert(_STACK *st, void *data, int loc) |
152 | { | ||
144 | char **s; | 153 | char **s; |
145 | 154 | ||
146 | if(st == NULL) return 0; | 155 | if (st == NULL) |
147 | if (st->num_alloc <= st->num+1) | 156 | return 0; |
148 | { | 157 | if (st->num_alloc <= st->num + 1) { |
149 | s=realloc((char *)st->data, | 158 | s = realloc((char *)st->data, |
150 | (unsigned int)sizeof(char *)*st->num_alloc*2); | 159 | (unsigned int)sizeof(char *) * st->num_alloc * 2); |
151 | if (s == NULL) | 160 | if (s == NULL) |
152 | return(0); | 161 | return (0); |
153 | st->data=s; | 162 | st->data = s; |
154 | st->num_alloc*=2; | 163 | st->num_alloc *= 2; |
155 | } | 164 | } |
156 | if ((loc >= (int)st->num) || (loc < 0)) | 165 | if ((loc >= (int)st->num) || (loc < 0)) |
157 | st->data[st->num]=data; | 166 | st->data[st->num] = data; |
158 | else | 167 | else { |
159 | { | ||
160 | int i; | 168 | int i; |
161 | char **f,**t; | 169 | char **f, **t; |
170 | |||
171 | f = st->data; | ||
172 | t = &(st->data[1]); | ||
173 | for (i = st->num; i >= loc; i--) | ||
174 | t[i] = f[i]; | ||
162 | 175 | ||
163 | f=st->data; | ||
164 | t=&(st->data[1]); | ||
165 | for (i=st->num; i>=loc; i--) | ||
166 | t[i]=f[i]; | ||
167 | |||
168 | #ifdef undef /* no memmove on sunos :-( */ | 176 | #ifdef undef /* no memmove on sunos :-( */ |
169 | memmove(&(st->data[loc+1]), | 177 | memmove(&(st->data[loc + 1]), |
170 | &(st->data[loc]), | 178 | &(st->data[loc]), |
171 | sizeof(char *)*(st->num-loc)); | 179 | sizeof(char *)*(st->num - loc)); |
172 | #endif | 180 | #endif |
173 | st->data[loc]=data; | 181 | st->data[loc] = data; |
174 | } | ||
175 | st->num++; | ||
176 | st->sorted=0; | ||
177 | return(st->num); | ||
178 | } | 182 | } |
183 | st->num++; | ||
184 | st->sorted = 0; | ||
185 | return (st->num); | ||
186 | } | ||
179 | 187 | ||
180 | void *sk_delete_ptr(_STACK *st, void *p) | 188 | void * |
181 | { | 189 | sk_delete_ptr(_STACK *st, void *p) |
190 | { | ||
182 | int i; | 191 | int i; |
183 | 192 | ||
184 | for (i=0; i<st->num; i++) | 193 | for (i = 0; i < st->num; i++) |
185 | if (st->data[i] == p) | 194 | if (st->data[i] == p) |
186 | return(sk_delete(st,i)); | 195 | return (sk_delete(st, i)); |
187 | return(NULL); | 196 | return (NULL); |
188 | } | 197 | } |
189 | 198 | ||
190 | void *sk_delete(_STACK *st, int loc) | 199 | void * |
191 | { | 200 | sk_delete(_STACK *st, int loc) |
201 | { | ||
192 | char *ret; | 202 | char *ret; |
193 | int i,j; | 203 | int i, j; |
194 | 204 | ||
195 | if(!st || (loc < 0) || (loc >= st->num)) return NULL; | 205 | if (!st || (loc < 0) || (loc >= st->num)) |
206 | return NULL; | ||
196 | 207 | ||
197 | ret=st->data[loc]; | 208 | ret = st->data[loc]; |
198 | if (loc != st->num-1) | 209 | if (loc != st->num - 1) { |
199 | { | 210 | j = st->num - 1; |
200 | j=st->num-1; | 211 | for (i = loc; i < j; i++) |
201 | for (i=loc; i<j; i++) | 212 | st->data[i] = st->data[i + 1]; |
202 | st->data[i]=st->data[i+1]; | ||
203 | /* In theory memcpy is not safe for this | 213 | /* In theory memcpy is not safe for this |
204 | * memcpy( &(st->data[loc]), | 214 | * memcpy( &(st->data[loc]), |
205 | * &(st->data[loc+1]), | 215 | * &(st->data[loc+1]), |
206 | * sizeof(char *)*(st->num-loc-1)); | 216 | * sizeof(char *)*(st->num-loc-1)); |
207 | */ | 217 | */ |
208 | } | ||
209 | st->num--; | ||
210 | return(ret); | ||
211 | } | 218 | } |
219 | st->num--; | ||
220 | return (ret); | ||
221 | } | ||
212 | 222 | ||
213 | static int internal_find(_STACK *st, void *data, int ret_val_options) | 223 | static int |
214 | { | 224 | internal_find(_STACK *st, void *data, int ret_val_options) |
225 | { | ||
215 | const void * const *r; | 226 | const void * const *r; |
216 | int i; | 227 | int i; |
217 | 228 | ||
218 | if(st == NULL) return -1; | 229 | if (st == NULL) |
230 | return -1; | ||
219 | 231 | ||
220 | if (st->comp == NULL) | 232 | if (st->comp == NULL) { |
221 | { | 233 | for (i = 0; i < st->num; i++) |
222 | for (i=0; i<st->num; i++) | ||
223 | if (st->data[i] == data) | 234 | if (st->data[i] == data) |
224 | return(i); | 235 | return (i); |
225 | return(-1); | 236 | return (-1); |
226 | } | ||
227 | sk_sort(st); | ||
228 | if (data == NULL) return(-1); | ||
229 | r=OBJ_bsearch_ex_(&data,st->data,st->num,sizeof(void *),st->comp, | ||
230 | ret_val_options); | ||
231 | if (r == NULL) return(-1); | ||
232 | return (int)((char **)r-st->data); | ||
233 | } | 237 | } |
238 | sk_sort(st); | ||
239 | if (data == NULL) | ||
240 | return (-1); | ||
241 | r = OBJ_bsearch_ex_(&data, st->data, st->num, sizeof(void *), st->comp, | ||
242 | ret_val_options); | ||
243 | if (r == NULL) | ||
244 | return (-1); | ||
245 | return (int)((char **)r - st->data); | ||
246 | } | ||
234 | 247 | ||
235 | int sk_find(_STACK *st, void *data) | 248 | int |
236 | { | 249 | sk_find(_STACK *st, void *data) |
250 | { | ||
237 | return internal_find(st, data, OBJ_BSEARCH_FIRST_VALUE_ON_MATCH); | 251 | return internal_find(st, data, OBJ_BSEARCH_FIRST_VALUE_ON_MATCH); |
238 | } | 252 | } |
239 | int sk_find_ex(_STACK *st, void *data) | 253 | |
240 | { | 254 | int |
255 | sk_find_ex(_STACK *st, void *data) | ||
256 | { | ||
241 | return internal_find(st, data, OBJ_BSEARCH_VALUE_ON_NOMATCH); | 257 | return internal_find(st, data, OBJ_BSEARCH_VALUE_ON_NOMATCH); |
242 | } | 258 | } |
243 | 259 | ||
244 | int sk_push(_STACK *st, void *data) | 260 | int |
245 | { | 261 | sk_push(_STACK *st, void *data) |
246 | return(sk_insert(st,data,st->num)); | 262 | { |
247 | } | 263 | return (sk_insert(st, data, st->num)); |
264 | } | ||
248 | 265 | ||
249 | int sk_unshift(_STACK *st, void *data) | 266 | int |
250 | { | 267 | sk_unshift(_STACK *st, void *data) |
251 | return(sk_insert(st,data,0)); | 268 | { |
252 | } | 269 | return (sk_insert(st, data, 0)); |
270 | } | ||
253 | 271 | ||
254 | void *sk_shift(_STACK *st) | 272 | void * |
255 | { | 273 | sk_shift(_STACK *st) |
256 | if (st == NULL) return(NULL); | 274 | { |
257 | if (st->num <= 0) return(NULL); | 275 | if (st == NULL) |
258 | return(sk_delete(st,0)); | 276 | return (NULL); |
259 | } | 277 | if (st->num <= 0) |
278 | return (NULL); | ||
279 | return (sk_delete(st, 0)); | ||
280 | } | ||
260 | 281 | ||
261 | void *sk_pop(_STACK *st) | 282 | void * |
262 | { | 283 | sk_pop(_STACK *st) |
263 | if (st == NULL) return(NULL); | 284 | { |
264 | if (st->num <= 0) return(NULL); | 285 | if (st == NULL) |
265 | return(sk_delete(st,st->num-1)); | 286 | return (NULL); |
266 | } | 287 | if (st->num <= 0) |
288 | return (NULL); | ||
289 | return (sk_delete(st, st->num - 1)); | ||
290 | } | ||
267 | 291 | ||
268 | void sk_zero(_STACK *st) | 292 | void |
269 | { | 293 | sk_zero(_STACK *st) |
270 | if (st == NULL) return; | 294 | { |
271 | if (st->num <= 0) return; | 295 | if (st == NULL) |
272 | memset((char *)st->data,0,sizeof(st->data)*st->num); | 296 | return; |
273 | st->num=0; | 297 | if (st->num <= 0) |
274 | } | 298 | return; |
299 | memset((char *)st->data, 0, sizeof(st->data)*st->num); | ||
300 | st->num = 0; | ||
301 | } | ||
275 | 302 | ||
276 | void sk_pop_free(_STACK *st, void (*func)(void *)) | 303 | void |
277 | { | 304 | sk_pop_free(_STACK *st, void (*func)(void *)) |
305 | { | ||
278 | int i; | 306 | int i; |
279 | 307 | ||
280 | if (st == NULL) return; | 308 | if (st == NULL) |
281 | for (i=0; i<st->num; i++) | 309 | return; |
310 | for (i = 0; i < st->num; i++) | ||
282 | if (st->data[i] != NULL) | 311 | if (st->data[i] != NULL) |
283 | func(st->data[i]); | 312 | func(st->data[i]); |
284 | sk_free(st); | 313 | sk_free(st); |
285 | } | 314 | } |
286 | 315 | ||
287 | void sk_free(_STACK *st) | 316 | void |
288 | { | 317 | sk_free(_STACK *st) |
289 | if (st == NULL) return; | 318 | { |
290 | if (st->data != NULL) free(st->data); | 319 | if (st == NULL) |
320 | return; | ||
321 | if (st->data != NULL) | ||
322 | free(st->data); | ||
291 | free(st); | 323 | free(st); |
292 | } | 324 | } |
293 | 325 | ||
294 | int sk_num(const _STACK *st) | 326 | int |
327 | sk_num(const _STACK *st) | ||
295 | { | 328 | { |
296 | if(st == NULL) return -1; | 329 | if (st == NULL) |
330 | return -1; | ||
297 | return st->num; | 331 | return st->num; |
298 | } | 332 | } |
299 | 333 | ||
300 | void *sk_value(const _STACK *st, int i) | 334 | void * |
335 | sk_value(const _STACK *st, int i) | ||
301 | { | 336 | { |
302 | if(!st || (i < 0) || (i >= st->num)) return NULL; | 337 | if (!st || (i < 0) || (i >= st->num)) |
338 | return NULL; | ||
303 | return st->data[i]; | 339 | return st->data[i]; |
304 | } | 340 | } |
305 | 341 | ||
306 | void *sk_set(_STACK *st, int i, void *value) | 342 | void * |
343 | sk_set(_STACK *st, int i, void *value) | ||
307 | { | 344 | { |
308 | if(!st || (i < 0) || (i >= st->num)) return NULL; | 345 | if (!st || (i < 0) || (i >= st->num)) |
346 | return NULL; | ||
309 | return (st->data[i] = value); | 347 | return (st->data[i] = value); |
310 | } | 348 | } |
311 | 349 | ||
312 | void sk_sort(_STACK *st) | 350 | void |
313 | { | 351 | sk_sort(_STACK *st) |
314 | if (st && !st->sorted) | 352 | { |
315 | { | 353 | if (st && !st->sorted) { |
316 | int (*comp_func)(const void *,const void *); | 354 | int (*comp_func)(const void *, const void *); |
317 | 355 | ||
318 | /* same comment as in sk_find ... previously st->comp was declared | 356 | /* same comment as in sk_find ... previously st->comp was declared |
319 | * as a (void*,void*) callback type, but this made the population | 357 | * as a (void*,void*) callback type, but this made the population |
320 | * of the callback pointer illogical - our callbacks compare | 358 | * of the callback pointer illogical - our callbacks compare |
321 | * type** with type**, so we leave the casting until absolutely | 359 | * type** with type**, so we leave the casting until absolutely |
322 | * necessary (ie. "now"). */ | 360 | * necessary (ie. "now"). */ |
323 | comp_func=(int (*)(const void *,const void *))(st->comp); | 361 | comp_func = (int (*)(const void *, const void *))(st->comp); |
324 | qsort(st->data,st->num,sizeof(char *), comp_func); | 362 | qsort(st->data, st->num, sizeof(char *), comp_func); |
325 | st->sorted=1; | 363 | st->sorted = 1; |
326 | } | ||
327 | } | 364 | } |
365 | } | ||
328 | 366 | ||
329 | int sk_is_sorted(const _STACK *st) | 367 | int |
330 | { | 368 | sk_is_sorted(const _STACK *st) |
369 | { | ||
331 | if (!st) | 370 | if (!st) |
332 | return 1; | 371 | return 1; |
333 | return st->sorted; | 372 | return st->sorted; |
334 | } | 373 | } |
diff --git a/src/lib/libcrypto/stack/stack.h b/src/lib/libcrypto/stack/stack.h index ce35e554eb..45698f81bc 100644 --- a/src/lib/libcrypto/stack/stack.h +++ b/src/lib/libcrypto/stack/stack.h | |||
@@ -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,15 +63,14 @@ | |||
63 | extern "C" { | 63 | extern "C" { |
64 | #endif | 64 | #endif |
65 | 65 | ||
66 | typedef struct stack_st | 66 | typedef struct stack_st { |
67 | { | ||
68 | int num; | 67 | int num; |
69 | char **data; | 68 | char **data; |
70 | int sorted; | 69 | int sorted; |
71 | 70 | ||
72 | int num_alloc; | 71 | int num_alloc; |
73 | int (*comp)(const void *, const void *); | 72 | int (*comp)(const void *, const void *); |
74 | } _STACK; /* Use STACK_OF(...) instead */ | 73 | } _STACK; /* Use STACK_OF(...) instead */ |
75 | 74 | ||
76 | #define M_sk_num(sk) ((sk) ? (sk)->num:-1) | 75 | #define M_sk_num(sk) ((sk) ? (sk)->num:-1) |
77 | #define M_sk_value(sk,n) ((sk) ? (sk)->data[n] : NULL) | 76 | #define M_sk_value(sk,n) ((sk) ? (sk)->data[n] : NULL) |
@@ -95,8 +94,8 @@ int sk_unshift(_STACK *st, void *data); | |||
95 | void *sk_shift(_STACK *st); | 94 | void *sk_shift(_STACK *st); |
96 | void *sk_pop(_STACK *st); | 95 | void *sk_pop(_STACK *st); |
97 | void sk_zero(_STACK *st); | 96 | void sk_zero(_STACK *st); |
98 | int (*sk_set_cmp_func(_STACK *sk, int (*c)(const void *, const void *))) | 97 | int (*sk_set_cmp_func(_STACK *sk, int (*c)(const void *, const void *)))( |
99 | (const void *, const void *); | 98 | const void *, const void *); |
100 | _STACK *sk_dup(_STACK *st); | 99 | _STACK *sk_dup(_STACK *st); |
101 | void sk_sort(_STACK *st); | 100 | void sk_sort(_STACK *st); |
102 | int sk_is_sorted(const _STACK *st); | 101 | int sk_is_sorted(const _STACK *st); |
diff --git a/src/lib/libssl/src/crypto/stack/stack.c b/src/lib/libssl/src/crypto/stack/stack.c index dabf26d2cd..a409a7e967 100644 --- a/src/lib/libssl/src/crypto/stack/stack.c +++ b/src/lib/libssl/src/crypto/stack/stack.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 |
@@ -77,258 +77,297 @@ const char STACK_version[]="Stack" OPENSSL_VERSION_PTEXT; | |||
77 | 77 | ||
78 | #include <errno.h> | 78 | #include <errno.h> |
79 | 79 | ||
80 | int (*sk_set_cmp_func(_STACK *sk, int (*c)(const void *, const void *))) | 80 | int |
81 | (const void *, const void *) | 81 | (*sk_set_cmp_func(_STACK *sk, int (*c)(const void *, const void *)))( |
82 | { | 82 | const void *, const void *) |
83 | int (*old)(const void *,const void *)=sk->comp; | 83 | { |
84 | int (*old)(const void *, const void *) = sk->comp; | ||
84 | 85 | ||
85 | if (sk->comp != c) | 86 | if (sk->comp != c) |
86 | sk->sorted=0; | 87 | sk->sorted = 0; |
87 | sk->comp=c; | 88 | sk->comp = c; |
88 | 89 | ||
89 | return old; | 90 | return old; |
90 | } | 91 | } |
91 | 92 | ||
92 | _STACK *sk_dup(_STACK *sk) | 93 | _STACK * |
93 | { | 94 | sk_dup(_STACK *sk) |
95 | { | ||
94 | _STACK *ret; | 96 | _STACK *ret; |
95 | char **s; | 97 | char **s; |
96 | 98 | ||
97 | if ((ret=sk_new(sk->comp)) == NULL) goto err; | 99 | if ((ret = sk_new(sk->comp)) == NULL) |
98 | s=(char **)realloc((char *)ret->data, | 100 | goto err; |
99 | (unsigned int)sizeof(char *)*sk->num_alloc); | 101 | s = (char **)realloc((char *)ret->data, |
100 | if (s == NULL) goto err; | 102 | (unsigned int)sizeof(char *) * sk->num_alloc); |
101 | ret->data=s; | 103 | if (s == NULL) |
102 | 104 | goto err; | |
103 | ret->num=sk->num; | 105 | ret->data = s; |
104 | memcpy(ret->data,sk->data,sizeof(char *)*sk->num); | 106 | |
105 | ret->sorted=sk->sorted; | 107 | ret->num = sk->num; |
106 | ret->num_alloc=sk->num_alloc; | 108 | memcpy(ret->data, sk->data, sizeof(char *) * sk->num); |
107 | ret->comp=sk->comp; | 109 | ret->sorted = sk->sorted; |
108 | return(ret); | 110 | ret->num_alloc = sk->num_alloc; |
111 | ret->comp = sk->comp; | ||
112 | return (ret); | ||
113 | |||
109 | err: | 114 | err: |
110 | if(ret) | 115 | if (ret) |
111 | sk_free(ret); | 116 | sk_free(ret); |
112 | return(NULL); | 117 | return (NULL); |
113 | } | 118 | } |
114 | 119 | ||
115 | _STACK *sk_new_null(void) | 120 | _STACK * |
116 | { | 121 | sk_new_null(void) |
122 | { | ||
117 | return sk_new((int (*)(const void *, const void *))0); | 123 | return sk_new((int (*)(const void *, const void *))0); |
118 | } | 124 | } |
119 | 125 | ||
120 | _STACK *sk_new(int (*c)(const void *, const void *)) | 126 | _STACK * |
121 | { | 127 | sk_new(int (*c)(const void *, const void *)) |
128 | { | ||
122 | _STACK *ret; | 129 | _STACK *ret; |
123 | int i; | 130 | int i; |
124 | 131 | ||
125 | if ((ret=malloc(sizeof(_STACK))) == NULL) | 132 | if ((ret = malloc(sizeof(_STACK))) == NULL) |
126 | goto err; | 133 | goto err; |
127 | if ((ret->data=malloc(sizeof(char *)*MIN_NODES)) == NULL) | 134 | if ((ret->data = malloc(sizeof(char *) * MIN_NODES)) == NULL) |
128 | goto err; | 135 | goto err; |
129 | for (i=0; i<MIN_NODES; i++) | 136 | for (i = 0; i < MIN_NODES; i++) |
130 | ret->data[i]=NULL; | 137 | ret->data[i] = NULL; |
131 | ret->comp=c; | 138 | ret->comp = c; |
132 | ret->num_alloc=MIN_NODES; | 139 | ret->num_alloc = MIN_NODES; |
133 | ret->num=0; | 140 | ret->num = 0; |
134 | ret->sorted=0; | 141 | ret->sorted = 0; |
135 | return(ret); | 142 | return (ret); |
143 | |||
136 | err: | 144 | err: |
137 | if(ret) | 145 | if (ret) |
138 | free(ret); | 146 | free(ret); |
139 | return(NULL); | 147 | return (NULL); |
140 | } | 148 | } |
141 | 149 | ||
142 | int sk_insert(_STACK *st, void *data, int loc) | 150 | int |
143 | { | 151 | sk_insert(_STACK *st, void *data, int loc) |
152 | { | ||
144 | char **s; | 153 | char **s; |
145 | 154 | ||
146 | if(st == NULL) return 0; | 155 | if (st == NULL) |
147 | if (st->num_alloc <= st->num+1) | 156 | return 0; |
148 | { | 157 | if (st->num_alloc <= st->num + 1) { |
149 | s=realloc((char *)st->data, | 158 | s = realloc((char *)st->data, |
150 | (unsigned int)sizeof(char *)*st->num_alloc*2); | 159 | (unsigned int)sizeof(char *) * st->num_alloc * 2); |
151 | if (s == NULL) | 160 | if (s == NULL) |
152 | return(0); | 161 | return (0); |
153 | st->data=s; | 162 | st->data = s; |
154 | st->num_alloc*=2; | 163 | st->num_alloc *= 2; |
155 | } | 164 | } |
156 | if ((loc >= (int)st->num) || (loc < 0)) | 165 | if ((loc >= (int)st->num) || (loc < 0)) |
157 | st->data[st->num]=data; | 166 | st->data[st->num] = data; |
158 | else | 167 | else { |
159 | { | ||
160 | int i; | 168 | int i; |
161 | char **f,**t; | 169 | char **f, **t; |
170 | |||
171 | f = st->data; | ||
172 | t = &(st->data[1]); | ||
173 | for (i = st->num; i >= loc; i--) | ||
174 | t[i] = f[i]; | ||
162 | 175 | ||
163 | f=st->data; | ||
164 | t=&(st->data[1]); | ||
165 | for (i=st->num; i>=loc; i--) | ||
166 | t[i]=f[i]; | ||
167 | |||
168 | #ifdef undef /* no memmove on sunos :-( */ | 176 | #ifdef undef /* no memmove on sunos :-( */ |
169 | memmove(&(st->data[loc+1]), | 177 | memmove(&(st->data[loc + 1]), |
170 | &(st->data[loc]), | 178 | &(st->data[loc]), |
171 | sizeof(char *)*(st->num-loc)); | 179 | sizeof(char *)*(st->num - loc)); |
172 | #endif | 180 | #endif |
173 | st->data[loc]=data; | 181 | st->data[loc] = data; |
174 | } | ||
175 | st->num++; | ||
176 | st->sorted=0; | ||
177 | return(st->num); | ||
178 | } | 182 | } |
183 | st->num++; | ||
184 | st->sorted = 0; | ||
185 | return (st->num); | ||
186 | } | ||
179 | 187 | ||
180 | void *sk_delete_ptr(_STACK *st, void *p) | 188 | void * |
181 | { | 189 | sk_delete_ptr(_STACK *st, void *p) |
190 | { | ||
182 | int i; | 191 | int i; |
183 | 192 | ||
184 | for (i=0; i<st->num; i++) | 193 | for (i = 0; i < st->num; i++) |
185 | if (st->data[i] == p) | 194 | if (st->data[i] == p) |
186 | return(sk_delete(st,i)); | 195 | return (sk_delete(st, i)); |
187 | return(NULL); | 196 | return (NULL); |
188 | } | 197 | } |
189 | 198 | ||
190 | void *sk_delete(_STACK *st, int loc) | 199 | void * |
191 | { | 200 | sk_delete(_STACK *st, int loc) |
201 | { | ||
192 | char *ret; | 202 | char *ret; |
193 | int i,j; | 203 | int i, j; |
194 | 204 | ||
195 | if(!st || (loc < 0) || (loc >= st->num)) return NULL; | 205 | if (!st || (loc < 0) || (loc >= st->num)) |
206 | return NULL; | ||
196 | 207 | ||
197 | ret=st->data[loc]; | 208 | ret = st->data[loc]; |
198 | if (loc != st->num-1) | 209 | if (loc != st->num - 1) { |
199 | { | 210 | j = st->num - 1; |
200 | j=st->num-1; | 211 | for (i = loc; i < j; i++) |
201 | for (i=loc; i<j; i++) | 212 | st->data[i] = st->data[i + 1]; |
202 | st->data[i]=st->data[i+1]; | ||
203 | /* In theory memcpy is not safe for this | 213 | /* In theory memcpy is not safe for this |
204 | * memcpy( &(st->data[loc]), | 214 | * memcpy( &(st->data[loc]), |
205 | * &(st->data[loc+1]), | 215 | * &(st->data[loc+1]), |
206 | * sizeof(char *)*(st->num-loc-1)); | 216 | * sizeof(char *)*(st->num-loc-1)); |
207 | */ | 217 | */ |
208 | } | ||
209 | st->num--; | ||
210 | return(ret); | ||
211 | } | 218 | } |
219 | st->num--; | ||
220 | return (ret); | ||
221 | } | ||
212 | 222 | ||
213 | static int internal_find(_STACK *st, void *data, int ret_val_options) | 223 | static int |
214 | { | 224 | internal_find(_STACK *st, void *data, int ret_val_options) |
225 | { | ||
215 | const void * const *r; | 226 | const void * const *r; |
216 | int i; | 227 | int i; |
217 | 228 | ||
218 | if(st == NULL) return -1; | 229 | if (st == NULL) |
230 | return -1; | ||
219 | 231 | ||
220 | if (st->comp == NULL) | 232 | if (st->comp == NULL) { |
221 | { | 233 | for (i = 0; i < st->num; i++) |
222 | for (i=0; i<st->num; i++) | ||
223 | if (st->data[i] == data) | 234 | if (st->data[i] == data) |
224 | return(i); | 235 | return (i); |
225 | return(-1); | 236 | return (-1); |
226 | } | ||
227 | sk_sort(st); | ||
228 | if (data == NULL) return(-1); | ||
229 | r=OBJ_bsearch_ex_(&data,st->data,st->num,sizeof(void *),st->comp, | ||
230 | ret_val_options); | ||
231 | if (r == NULL) return(-1); | ||
232 | return (int)((char **)r-st->data); | ||
233 | } | 237 | } |
238 | sk_sort(st); | ||
239 | if (data == NULL) | ||
240 | return (-1); | ||
241 | r = OBJ_bsearch_ex_(&data, st->data, st->num, sizeof(void *), st->comp, | ||
242 | ret_val_options); | ||
243 | if (r == NULL) | ||
244 | return (-1); | ||
245 | return (int)((char **)r - st->data); | ||
246 | } | ||
234 | 247 | ||
235 | int sk_find(_STACK *st, void *data) | 248 | int |
236 | { | 249 | sk_find(_STACK *st, void *data) |
250 | { | ||
237 | return internal_find(st, data, OBJ_BSEARCH_FIRST_VALUE_ON_MATCH); | 251 | return internal_find(st, data, OBJ_BSEARCH_FIRST_VALUE_ON_MATCH); |
238 | } | 252 | } |
239 | int sk_find_ex(_STACK *st, void *data) | 253 | |
240 | { | 254 | int |
255 | sk_find_ex(_STACK *st, void *data) | ||
256 | { | ||
241 | return internal_find(st, data, OBJ_BSEARCH_VALUE_ON_NOMATCH); | 257 | return internal_find(st, data, OBJ_BSEARCH_VALUE_ON_NOMATCH); |
242 | } | 258 | } |
243 | 259 | ||
244 | int sk_push(_STACK *st, void *data) | 260 | int |
245 | { | 261 | sk_push(_STACK *st, void *data) |
246 | return(sk_insert(st,data,st->num)); | 262 | { |
247 | } | 263 | return (sk_insert(st, data, st->num)); |
264 | } | ||
248 | 265 | ||
249 | int sk_unshift(_STACK *st, void *data) | 266 | int |
250 | { | 267 | sk_unshift(_STACK *st, void *data) |
251 | return(sk_insert(st,data,0)); | 268 | { |
252 | } | 269 | return (sk_insert(st, data, 0)); |
270 | } | ||
253 | 271 | ||
254 | void *sk_shift(_STACK *st) | 272 | void * |
255 | { | 273 | sk_shift(_STACK *st) |
256 | if (st == NULL) return(NULL); | 274 | { |
257 | if (st->num <= 0) return(NULL); | 275 | if (st == NULL) |
258 | return(sk_delete(st,0)); | 276 | return (NULL); |
259 | } | 277 | if (st->num <= 0) |
278 | return (NULL); | ||
279 | return (sk_delete(st, 0)); | ||
280 | } | ||
260 | 281 | ||
261 | void *sk_pop(_STACK *st) | 282 | void * |
262 | { | 283 | sk_pop(_STACK *st) |
263 | if (st == NULL) return(NULL); | 284 | { |
264 | if (st->num <= 0) return(NULL); | 285 | if (st == NULL) |
265 | return(sk_delete(st,st->num-1)); | 286 | return (NULL); |
266 | } | 287 | if (st->num <= 0) |
288 | return (NULL); | ||
289 | return (sk_delete(st, st->num - 1)); | ||
290 | } | ||
267 | 291 | ||
268 | void sk_zero(_STACK *st) | 292 | void |
269 | { | 293 | sk_zero(_STACK *st) |
270 | if (st == NULL) return; | 294 | { |
271 | if (st->num <= 0) return; | 295 | if (st == NULL) |
272 | memset((char *)st->data,0,sizeof(st->data)*st->num); | 296 | return; |
273 | st->num=0; | 297 | if (st->num <= 0) |
274 | } | 298 | return; |
299 | memset((char *)st->data, 0, sizeof(st->data)*st->num); | ||
300 | st->num = 0; | ||
301 | } | ||
275 | 302 | ||
276 | void sk_pop_free(_STACK *st, void (*func)(void *)) | 303 | void |
277 | { | 304 | sk_pop_free(_STACK *st, void (*func)(void *)) |
305 | { | ||
278 | int i; | 306 | int i; |
279 | 307 | ||
280 | if (st == NULL) return; | 308 | if (st == NULL) |
281 | for (i=0; i<st->num; i++) | 309 | return; |
310 | for (i = 0; i < st->num; i++) | ||
282 | if (st->data[i] != NULL) | 311 | if (st->data[i] != NULL) |
283 | func(st->data[i]); | 312 | func(st->data[i]); |
284 | sk_free(st); | 313 | sk_free(st); |
285 | } | 314 | } |
286 | 315 | ||
287 | void sk_free(_STACK *st) | 316 | void |
288 | { | 317 | sk_free(_STACK *st) |
289 | if (st == NULL) return; | 318 | { |
290 | if (st->data != NULL) free(st->data); | 319 | if (st == NULL) |
320 | return; | ||
321 | if (st->data != NULL) | ||
322 | free(st->data); | ||
291 | free(st); | 323 | free(st); |
292 | } | 324 | } |
293 | 325 | ||
294 | int sk_num(const _STACK *st) | 326 | int |
327 | sk_num(const _STACK *st) | ||
295 | { | 328 | { |
296 | if(st == NULL) return -1; | 329 | if (st == NULL) |
330 | return -1; | ||
297 | return st->num; | 331 | return st->num; |
298 | } | 332 | } |
299 | 333 | ||
300 | void *sk_value(const _STACK *st, int i) | 334 | void * |
335 | sk_value(const _STACK *st, int i) | ||
301 | { | 336 | { |
302 | if(!st || (i < 0) || (i >= st->num)) return NULL; | 337 | if (!st || (i < 0) || (i >= st->num)) |
338 | return NULL; | ||
303 | return st->data[i]; | 339 | return st->data[i]; |
304 | } | 340 | } |
305 | 341 | ||
306 | void *sk_set(_STACK *st, int i, void *value) | 342 | void * |
343 | sk_set(_STACK *st, int i, void *value) | ||
307 | { | 344 | { |
308 | if(!st || (i < 0) || (i >= st->num)) return NULL; | 345 | if (!st || (i < 0) || (i >= st->num)) |
346 | return NULL; | ||
309 | return (st->data[i] = value); | 347 | return (st->data[i] = value); |
310 | } | 348 | } |
311 | 349 | ||
312 | void sk_sort(_STACK *st) | 350 | void |
313 | { | 351 | sk_sort(_STACK *st) |
314 | if (st && !st->sorted) | 352 | { |
315 | { | 353 | if (st && !st->sorted) { |
316 | int (*comp_func)(const void *,const void *); | 354 | int (*comp_func)(const void *, const void *); |
317 | 355 | ||
318 | /* same comment as in sk_find ... previously st->comp was declared | 356 | /* same comment as in sk_find ... previously st->comp was declared |
319 | * as a (void*,void*) callback type, but this made the population | 357 | * as a (void*,void*) callback type, but this made the population |
320 | * of the callback pointer illogical - our callbacks compare | 358 | * of the callback pointer illogical - our callbacks compare |
321 | * type** with type**, so we leave the casting until absolutely | 359 | * type** with type**, so we leave the casting until absolutely |
322 | * necessary (ie. "now"). */ | 360 | * necessary (ie. "now"). */ |
323 | comp_func=(int (*)(const void *,const void *))(st->comp); | 361 | comp_func = (int (*)(const void *, const void *))(st->comp); |
324 | qsort(st->data,st->num,sizeof(char *), comp_func); | 362 | qsort(st->data, st->num, sizeof(char *), comp_func); |
325 | st->sorted=1; | 363 | st->sorted = 1; |
326 | } | ||
327 | } | 364 | } |
365 | } | ||
328 | 366 | ||
329 | int sk_is_sorted(const _STACK *st) | 367 | int |
330 | { | 368 | sk_is_sorted(const _STACK *st) |
369 | { | ||
331 | if (!st) | 370 | if (!st) |
332 | return 1; | 371 | return 1; |
333 | return st->sorted; | 372 | return st->sorted; |
334 | } | 373 | } |
diff --git a/src/lib/libssl/src/crypto/stack/stack.h b/src/lib/libssl/src/crypto/stack/stack.h index ce35e554eb..45698f81bc 100644 --- a/src/lib/libssl/src/crypto/stack/stack.h +++ b/src/lib/libssl/src/crypto/stack/stack.h | |||
@@ -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,15 +63,14 @@ | |||
63 | extern "C" { | 63 | extern "C" { |
64 | #endif | 64 | #endif |
65 | 65 | ||
66 | typedef struct stack_st | 66 | typedef struct stack_st { |
67 | { | ||
68 | int num; | 67 | int num; |
69 | char **data; | 68 | char **data; |
70 | int sorted; | 69 | int sorted; |
71 | 70 | ||
72 | int num_alloc; | 71 | int num_alloc; |
73 | int (*comp)(const void *, const void *); | 72 | int (*comp)(const void *, const void *); |
74 | } _STACK; /* Use STACK_OF(...) instead */ | 73 | } _STACK; /* Use STACK_OF(...) instead */ |
75 | 74 | ||
76 | #define M_sk_num(sk) ((sk) ? (sk)->num:-1) | 75 | #define M_sk_num(sk) ((sk) ? (sk)->num:-1) |
77 | #define M_sk_value(sk,n) ((sk) ? (sk)->data[n] : NULL) | 76 | #define M_sk_value(sk,n) ((sk) ? (sk)->data[n] : NULL) |
@@ -95,8 +94,8 @@ int sk_unshift(_STACK *st, void *data); | |||
95 | void *sk_shift(_STACK *st); | 94 | void *sk_shift(_STACK *st); |
96 | void *sk_pop(_STACK *st); | 95 | void *sk_pop(_STACK *st); |
97 | void sk_zero(_STACK *st); | 96 | void sk_zero(_STACK *st); |
98 | int (*sk_set_cmp_func(_STACK *sk, int (*c)(const void *, const void *))) | 97 | int (*sk_set_cmp_func(_STACK *sk, int (*c)(const void *, const void *)))( |
99 | (const void *, const void *); | 98 | const void *, const void *); |
100 | _STACK *sk_dup(_STACK *st); | 99 | _STACK *sk_dup(_STACK *st); |
101 | void sk_sort(_STACK *st); | 100 | void sk_sort(_STACK *st); |
102 | int sk_is_sorted(const _STACK *st); | 101 | int sk_is_sorted(const _STACK *st); |