summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/bn/bn_mont.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/bn/bn_mont.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/bn/bn_mont.c')
-rw-r--r--src/lib/libcrypto/bn/bn_mont.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/src/lib/libcrypto/bn/bn_mont.c b/src/lib/libcrypto/bn/bn_mont.c
index 5803ca493d..3eb9913a9e 100644
--- a/src/lib/libcrypto/bn/bn_mont.c
+++ b/src/lib/libcrypto/bn/bn_mont.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_mont.c,v 1.23 2014/07/11 08:44:48 jsing Exp $ */ 1/* $OpenBSD: bn_mont.c,v 1.24 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 *
@@ -149,8 +149,7 @@ BN_mod_mul_montgomery(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
149#endif 149#endif
150 150
151 BN_CTX_start(ctx); 151 BN_CTX_start(ctx);
152 tmp = BN_CTX_get(ctx); 152 if ((tmp = BN_CTX_get(ctx)) == NULL)
153 if (tmp == NULL)
154 goto err; 153 goto err;
155 154
156 bn_check_top(tmp); 155 bn_check_top(tmp);
@@ -288,9 +287,9 @@ BN_from_montgomery(BIGNUM *ret, const BIGNUM *a, BN_MONT_CTX *mont, BN_CTX *ctx)
288 BIGNUM *t1, *t2; 287 BIGNUM *t1, *t2;
289 288
290 BN_CTX_start(ctx); 289 BN_CTX_start(ctx);
291 t1 = BN_CTX_get(ctx); 290 if ((t1 = BN_CTX_get(ctx)) == NULL)
292 t2 = BN_CTX_get(ctx); 291 goto err;
293 if (t1 == NULL || t2 == NULL) 292 if ((t2 = BN_CTX_get(ctx)) == NULL)
294 goto err; 293 goto err;
295 294
296 if (!BN_copy(t1, a)) 295 if (!BN_copy(t1, a))