diff options
author | tedu <> | 2014-06-19 21:23:48 +0000 |
---|---|---|
committer | tedu <> | 2014-06-19 21:23:48 +0000 |
commit | a53e20a6c040532f3fcfd5a73b1b493e8f09163a (patch) | |
tree | 5490d1df31b217d6b4a7607827df982ad950733f /src | |
parent | 621a34760179b1387de8337f525f1c9dedf54fad (diff) | |
download | openbsd-a53e20a6c040532f3fcfd5a73b1b493e8f09163a.tar.gz openbsd-a53e20a6c040532f3fcfd5a73b1b493e8f09163a.tar.bz2 openbsd-a53e20a6c040532f3fcfd5a73b1b493e8f09163a.zip |
improve error checking. set error code on error, and check malloc return.
add missing unlock in one case. ok lteo miod
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libcrypto/x509/by_dir.c | 15 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/x509/by_dir.c | 15 |
2 files changed, 26 insertions, 4 deletions
diff --git a/src/lib/libcrypto/x509/by_dir.c b/src/lib/libcrypto/x509/by_dir.c index 21aa464962..21ba0a7bc2 100644 --- a/src/lib/libcrypto/x509/by_dir.c +++ b/src/lib/libcrypto/x509/by_dir.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: by_dir.c,v 1.26 2014/06/12 15:49:31 deraadt Exp $ */ | 1 | /* $OpenBSD: by_dir.c,v 1.27 2014/06/19 21:23:48 tedu Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -241,16 +241,20 @@ add_cert_dir(BY_DIR *ctx, const char *dir, int type) | |||
241 | } | 241 | } |
242 | } | 242 | } |
243 | ent = malloc(sizeof(BY_DIR_ENTRY)); | 243 | ent = malloc(sizeof(BY_DIR_ENTRY)); |
244 | if (!ent) | 244 | if (!ent) { |
245 | X509err(X509_F_ADD_CERT_DIR, ERR_R_MALLOC_FAILURE); | ||
245 | return 0; | 246 | return 0; |
247 | } | ||
246 | ent->dir_type = type; | 248 | ent->dir_type = type; |
247 | ent->hashes = sk_BY_DIR_HASH_new(by_dir_hash_cmp); | 249 | ent->hashes = sk_BY_DIR_HASH_new(by_dir_hash_cmp); |
248 | ent->dir = strdup(ss); | 250 | ent->dir = strdup(ss); |
249 | if (!ent->dir || !ent->hashes) { | 251 | if (!ent->dir || !ent->hashes) { |
252 | X509err(X509_F_ADD_CERT_DIR, ERR_R_MALLOC_FAILURE); | ||
250 | by_dir_entry_free(ent); | 253 | by_dir_entry_free(ent); |
251 | return 0; | 254 | return 0; |
252 | } | 255 | } |
253 | if (!sk_BY_DIR_ENTRY_push(ctx->dirs, ent)) { | 256 | if (!sk_BY_DIR_ENTRY_push(ctx->dirs, ent)) { |
257 | X509err(X509_F_ADD_CERT_DIR, ERR_R_MALLOC_FAILURE); | ||
254 | by_dir_entry_free(ent); | 258 | by_dir_entry_free(ent); |
255 | return 0; | 259 | return 0; |
256 | } | 260 | } |
@@ -384,9 +388,16 @@ get_cert_by_subject(X509_LOOKUP *xl, int type, X509_NAME *name, | |||
384 | } | 388 | } |
385 | if (!hent) { | 389 | if (!hent) { |
386 | hent = malloc(sizeof(BY_DIR_HASH)); | 390 | hent = malloc(sizeof(BY_DIR_HASH)); |
391 | if (!hent) { | ||
392 | X509err(X509_F_GET_CERT_BY_SUBJECT, ERR_R_MALLOC_FAILURE); | ||
393 | CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE); | ||
394 | ok = 0; | ||
395 | goto finish; | ||
396 | } | ||
387 | hent->hash = h; | 397 | hent->hash = h; |
388 | hent->suffix = k; | 398 | hent->suffix = k; |
389 | if (!sk_BY_DIR_HASH_push(ent->hashes, hent)) { | 399 | if (!sk_BY_DIR_HASH_push(ent->hashes, hent)) { |
400 | X509err(X509_F_GET_CERT_BY_SUBJECT, ERR_R_MALLOC_FAILURE); | ||
390 | CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE); | 401 | CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE); |
391 | free(hent); | 402 | free(hent); |
392 | ok = 0; | 403 | ok = 0; |
diff --git a/src/lib/libssl/src/crypto/x509/by_dir.c b/src/lib/libssl/src/crypto/x509/by_dir.c index 21aa464962..21ba0a7bc2 100644 --- a/src/lib/libssl/src/crypto/x509/by_dir.c +++ b/src/lib/libssl/src/crypto/x509/by_dir.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: by_dir.c,v 1.26 2014/06/12 15:49:31 deraadt Exp $ */ | 1 | /* $OpenBSD: by_dir.c,v 1.27 2014/06/19 21:23:48 tedu Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -241,16 +241,20 @@ add_cert_dir(BY_DIR *ctx, const char *dir, int type) | |||
241 | } | 241 | } |
242 | } | 242 | } |
243 | ent = malloc(sizeof(BY_DIR_ENTRY)); | 243 | ent = malloc(sizeof(BY_DIR_ENTRY)); |
244 | if (!ent) | 244 | if (!ent) { |
245 | X509err(X509_F_ADD_CERT_DIR, ERR_R_MALLOC_FAILURE); | ||
245 | return 0; | 246 | return 0; |
247 | } | ||
246 | ent->dir_type = type; | 248 | ent->dir_type = type; |
247 | ent->hashes = sk_BY_DIR_HASH_new(by_dir_hash_cmp); | 249 | ent->hashes = sk_BY_DIR_HASH_new(by_dir_hash_cmp); |
248 | ent->dir = strdup(ss); | 250 | ent->dir = strdup(ss); |
249 | if (!ent->dir || !ent->hashes) { | 251 | if (!ent->dir || !ent->hashes) { |
252 | X509err(X509_F_ADD_CERT_DIR, ERR_R_MALLOC_FAILURE); | ||
250 | by_dir_entry_free(ent); | 253 | by_dir_entry_free(ent); |
251 | return 0; | 254 | return 0; |
252 | } | 255 | } |
253 | if (!sk_BY_DIR_ENTRY_push(ctx->dirs, ent)) { | 256 | if (!sk_BY_DIR_ENTRY_push(ctx->dirs, ent)) { |
257 | X509err(X509_F_ADD_CERT_DIR, ERR_R_MALLOC_FAILURE); | ||
254 | by_dir_entry_free(ent); | 258 | by_dir_entry_free(ent); |
255 | return 0; | 259 | return 0; |
256 | } | 260 | } |
@@ -384,9 +388,16 @@ get_cert_by_subject(X509_LOOKUP *xl, int type, X509_NAME *name, | |||
384 | } | 388 | } |
385 | if (!hent) { | 389 | if (!hent) { |
386 | hent = malloc(sizeof(BY_DIR_HASH)); | 390 | hent = malloc(sizeof(BY_DIR_HASH)); |
391 | if (!hent) { | ||
392 | X509err(X509_F_GET_CERT_BY_SUBJECT, ERR_R_MALLOC_FAILURE); | ||
393 | CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE); | ||
394 | ok = 0; | ||
395 | goto finish; | ||
396 | } | ||
387 | hent->hash = h; | 397 | hent->hash = h; |
388 | hent->suffix = k; | 398 | hent->suffix = k; |
389 | if (!sk_BY_DIR_HASH_push(ent->hashes, hent)) { | 399 | if (!sk_BY_DIR_HASH_push(ent->hashes, hent)) { |
400 | X509err(X509_F_GET_CERT_BY_SUBJECT, ERR_R_MALLOC_FAILURE); | ||
390 | CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE); | 401 | CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE); |
391 | free(hent); | 402 | free(hent); |
392 | ok = 0; | 403 | ok = 0; |