|
1 | 1 | /* |
2 | | - * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. |
| 2 | + * Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved. |
3 | 3 | * |
4 | 4 | * Licensed under the OpenSSL license (the "License"). You may not use |
5 | 5 | * this file except in compliance with the License. You can obtain a copy |
@@ -290,73 +290,58 @@ int X509_STORE_CTX_get_by_subject(X509_STORE_CTX *vs, X509_LOOKUP_TYPE type, |
290 | 290 | return 1; |
291 | 291 | } |
292 | 292 |
|
293 | | -int X509_STORE_add_cert(X509_STORE *ctx, X509 *x) |
294 | | -{ |
| 293 | +static int x509_store_add(X509_STORE *ctx, void *x, int crl) { |
295 | 294 | X509_OBJECT *obj; |
296 | | - int ret = 1, added = 1; |
| 295 | + int ret = 0, added = 0; |
297 | 296 |
|
298 | 297 | if (x == NULL) |
299 | 298 | return 0; |
300 | 299 | obj = X509_OBJECT_new(); |
301 | 300 | if (obj == NULL) |
302 | 301 | return 0; |
303 | | - obj->type = X509_LU_X509; |
304 | | - obj->data.x509 = x; |
| 302 | + |
| 303 | + if (crl) { |
| 304 | + obj->type = X509_LU_CRL; |
| 305 | + obj->data.crl = (X509_CRL *)x; |
| 306 | + } else { |
| 307 | + obj->type = X509_LU_X509; |
| 308 | + obj->data.x509 = (X509 *)x; |
| 309 | + } |
305 | 310 | X509_OBJECT_up_ref_count(obj); |
306 | 311 |
|
307 | 312 | CRYPTO_THREAD_write_lock(ctx->lock); |
308 | 313 |
|
309 | 314 | if (X509_OBJECT_retrieve_match(ctx->objs, obj)) { |
310 | | - X509err(X509_F_X509_STORE_ADD_CERT, |
311 | | - X509_R_CERT_ALREADY_IN_HASH_TABLE); |
312 | | - ret = 0; |
| 315 | + ret = 1; |
313 | 316 | } else { |
314 | 317 | added = sk_X509_OBJECT_push(ctx->objs, obj); |
315 | 318 | ret = added != 0; |
316 | 319 | } |
317 | 320 |
|
318 | 321 | CRYPTO_THREAD_unlock(ctx->lock); |
319 | 322 |
|
320 | | - if (!ret) /* obj not pushed */ |
| 323 | + if (added == 0) /* obj not pushed */ |
321 | 324 | X509_OBJECT_free(obj); |
322 | | - if (!added) /* on push failure */ |
323 | | - X509err(X509_F_X509_STORE_ADD_CERT, ERR_R_MALLOC_FAILURE); |
324 | 325 |
|
325 | 326 | return ret; |
326 | 327 | } |
327 | 328 |
|
328 | | -int X509_STORE_add_crl(X509_STORE *ctx, X509_CRL *x) |
| 329 | +int X509_STORE_add_cert(X509_STORE *ctx, X509 *x) |
329 | 330 | { |
330 | | - X509_OBJECT *obj; |
331 | | - int ret = 1, added = 1; |
332 | | - |
333 | | - if (x == NULL) |
334 | | - return 0; |
335 | | - obj = X509_OBJECT_new(); |
336 | | - if (obj == NULL) |
| 331 | + if (!x509_store_add(ctx, x, 0)) { |
| 332 | + X509err(X509_F_X509_STORE_ADD_CERT, ERR_R_MALLOC_FAILURE); |
337 | 333 | return 0; |
338 | | - obj->type = X509_LU_CRL; |
339 | | - obj->data.crl = x; |
340 | | - X509_OBJECT_up_ref_count(obj); |
341 | | - |
342 | | - CRYPTO_THREAD_write_lock(ctx->lock); |
343 | | - |
344 | | - if (X509_OBJECT_retrieve_match(ctx->objs, obj)) { |
345 | | - X509err(X509_F_X509_STORE_ADD_CRL, X509_R_CERT_ALREADY_IN_HASH_TABLE); |
346 | | - ret = 0; |
347 | | - } else { |
348 | | - added = sk_X509_OBJECT_push(ctx->objs, obj); |
349 | | - ret = added != 0; |
350 | 334 | } |
| 335 | + return 1; |
| 336 | +} |
351 | 337 |
|
352 | | - CRYPTO_THREAD_unlock(ctx->lock); |
353 | | - |
354 | | - if (!ret) /* obj not pushed */ |
355 | | - X509_OBJECT_free(obj); |
356 | | - if (!added) /* on push failure */ |
| 338 | +int X509_STORE_add_crl(X509_STORE *ctx, X509_CRL *x) |
| 339 | +{ |
| 340 | + if (!x509_store_add(ctx, x, 1)) { |
357 | 341 | X509err(X509_F_X509_STORE_ADD_CRL, ERR_R_MALLOC_FAILURE); |
358 | | - |
359 | | - return ret; |
| 342 | + return 0; |
| 343 | + } |
| 344 | + return 1; |
360 | 345 | } |
361 | 346 |
|
362 | 347 | int X509_OBJECT_up_ref_count(X509_OBJECT *a) |
|
0 commit comments