summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/rsa/rsa_gen.c
diff options
context:
space:
mode:
authorjsing <>2015-02-09 15:49:22 +0000
committerjsing <>2015-02-09 15:49:22 +0000
commit16f790d01f7a6fc6c94e2a033a67b80c8ec5291c (patch)
treed924c624d5eb949a9e7e395dc99d92616e911ce9 /src/lib/libcrypto/rsa/rsa_gen.c
parent42f7780549de5b7b5e3e7943cfef87e0e41970fc (diff)
downloadopenbsd-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/rsa/rsa_gen.c')
-rw-r--r--src/lib/libcrypto/rsa/rsa_gen.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/lib/libcrypto/rsa/rsa_gen.c b/src/lib/libcrypto/rsa/rsa_gen.c
index a3b9da4856..f6f051c442 100644
--- a/src/lib/libcrypto/rsa/rsa_gen.c
+++ b/src/lib/libcrypto/rsa/rsa_gen.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: rsa_gen.c,v 1.16 2014/07/11 08:44:49 jsing Exp $ */ 1/* $OpenBSD: rsa_gen.c,v 1.17 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 *
@@ -99,11 +99,13 @@ rsa_builtin_keygen(RSA *rsa, int bits, BIGNUM *e_value, BN_GENCB *cb)
99 if (ctx == NULL) 99 if (ctx == NULL)
100 goto err; 100 goto err;
101 BN_CTX_start(ctx); 101 BN_CTX_start(ctx);
102 r0 = BN_CTX_get(ctx); 102 if ((r0 = BN_CTX_get(ctx)) == NULL)
103 r1 = BN_CTX_get(ctx); 103 goto err;
104 r2 = BN_CTX_get(ctx); 104 if ((r1 = BN_CTX_get(ctx)) == NULL)
105 r3 = BN_CTX_get(ctx); 105 goto err;
106 if (r3 == NULL) 106 if ((r2 = BN_CTX_get(ctx)) == NULL)
107 goto err;
108 if ((r3 = BN_CTX_get(ctx)) == NULL)
107 goto err; 109 goto err;
108 110
109 bitsp = (bits + 1) / 2; 111 bitsp = (bits + 1) / 2;