diff options
author | jsing <> | 2015-02-09 15:49:22 +0000 |
---|---|---|
committer | jsing <> | 2015-02-09 15:49:22 +0000 |
commit | 16f790d01f7a6fc6c94e2a033a67b80c8ec5291c (patch) | |
tree | d924c624d5eb949a9e7e395dc99d92616e911ce9 /src/lib/libcrypto/dh | |
parent | 42f7780549de5b7b5e3e7943cfef87e0e41970fc (diff) | |
download | openbsd-16f790d01f7a6fc6c94e2a033a67b80c8ec5291c.tar.gz openbsd-16f790d01f7a6fc6c94e2a033a67b80c8ec5291c.tar.bz2 openbsd-16f790d01f7a6fc6c94e2a033a67b80c8ec5291c.zip |
BN_CTX_get() can fail - consistently check its return value.
There are currently cases where the return from each call is checked,
the return from only the last call is checked and cases where it is not
checked at all (including code in bn, ec and engine).
Checking the last return value is valid as once the function fails it will
continue to return NULL. However, in order to be consistent check each
call with the same idiom. This makes it easy to verify.
Note there are still a handful of cases that do not follow the idiom -
these will be handled separately.
ok beck@ doug@
Diffstat (limited to 'src/lib/libcrypto/dh')
-rw-r--r-- | src/lib/libcrypto/dh/dh_gen.c | 8 | ||||
-rw-r--r-- | src/lib/libcrypto/dh/dh_key.c | 5 |
2 files changed, 7 insertions, 6 deletions
diff --git a/src/lib/libcrypto/dh/dh_gen.c b/src/lib/libcrypto/dh/dh_gen.c index 1bc37b987e..de566802d3 100644 --- a/src/lib/libcrypto/dh/dh_gen.c +++ b/src/lib/libcrypto/dh/dh_gen.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: dh_gen.c,v 1.14 2015/02/07 13:19:15 doug Exp $ */ | 1 | /* $OpenBSD: dh_gen.c,v 1.15 2015/02/09 15:49:22 jsing 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 | * |
@@ -115,9 +115,9 @@ dh_builtin_genparams(DH *ret, int prime_len, int generator, BN_GENCB *cb) | |||
115 | if (ctx == NULL) | 115 | if (ctx == NULL) |
116 | goto err; | 116 | goto err; |
117 | BN_CTX_start(ctx); | 117 | BN_CTX_start(ctx); |
118 | t1 = BN_CTX_get(ctx); | 118 | if ((t1 = BN_CTX_get(ctx)) == NULL) |
119 | t2 = BN_CTX_get(ctx); | 119 | goto err; |
120 | if (t1 == NULL || t2 == NULL) | 120 | if ((t2 = BN_CTX_get(ctx)) == NULL) |
121 | goto err; | 121 | goto err; |
122 | 122 | ||
123 | /* Make sure 'ret' has the necessary elements */ | 123 | /* Make sure 'ret' has the necessary elements */ |
diff --git a/src/lib/libcrypto/dh/dh_key.c b/src/lib/libcrypto/dh/dh_key.c index b8352149e2..31bc7b3dfd 100644 --- a/src/lib/libcrypto/dh/dh_key.c +++ b/src/lib/libcrypto/dh/dh_key.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: dh_key.c,v 1.22 2014/10/18 17:20:40 jsing Exp $ */ | 1 | /* $OpenBSD: dh_key.c,v 1.23 2015/02/09 15:49:22 jsing 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 | * |
@@ -195,7 +195,8 @@ compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh) | |||
195 | if (ctx == NULL) | 195 | if (ctx == NULL) |
196 | goto err; | 196 | goto err; |
197 | BN_CTX_start(ctx); | 197 | BN_CTX_start(ctx); |
198 | tmp = BN_CTX_get(ctx); | 198 | if ((tmp = BN_CTX_get(ctx)) == NULL) |
199 | goto err; | ||
199 | 200 | ||
200 | if (dh->priv_key == NULL) { | 201 | if (dh->priv_key == NULL) { |
201 | DHerr(DH_F_COMPUTE_KEY, DH_R_NO_PRIVATE_VALUE); | 202 | DHerr(DH_F_COMPUTE_KEY, DH_R_NO_PRIVATE_VALUE); |