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/ec/ec_lib.c | |
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 '')
-rw-r--r-- | src/lib/libcrypto/ec/ec_lib.c | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/src/lib/libcrypto/ec/ec_lib.c b/src/lib/libcrypto/ec/ec_lib.c index 47ccc614d1..8cf0f2241e 100644 --- a/src/lib/libcrypto/ec/ec_lib.c +++ b/src/lib/libcrypto/ec/ec_lib.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ec_lib.c,v 1.15 2014/07/12 16:03:37 miod Exp $ */ | 1 | /* $OpenBSD: ec_lib.c,v 1.16 2015/02/09 15:49:22 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * Originally written by Bodo Moeller for the OpenSSL project. | 3 | * Originally written by Bodo Moeller for the OpenSSL project. |
4 | */ | 4 | */ |
@@ -497,18 +497,19 @@ EC_GROUP_cmp(const EC_GROUP * a, const EC_GROUP * b, BN_CTX * ctx) | |||
497 | return -1; | 497 | return -1; |
498 | 498 | ||
499 | BN_CTX_start(ctx); | 499 | BN_CTX_start(ctx); |
500 | a1 = BN_CTX_get(ctx); | 500 | if ((a1 = BN_CTX_get(ctx)) == NULL) |
501 | a2 = BN_CTX_get(ctx); | 501 | goto err; |
502 | a3 = BN_CTX_get(ctx); | 502 | if ((a2 = BN_CTX_get(ctx)) == NULL) |
503 | b1 = BN_CTX_get(ctx); | 503 | goto err; |
504 | b2 = BN_CTX_get(ctx); | 504 | if ((a3 = BN_CTX_get(ctx)) == NULL) |
505 | b3 = BN_CTX_get(ctx); | 505 | goto err; |
506 | if (!b3) { | 506 | if ((b1 = BN_CTX_get(ctx)) == NULL) |
507 | BN_CTX_end(ctx); | 507 | goto err; |
508 | if (ctx_new) | 508 | if ((b2 = BN_CTX_get(ctx)) == NULL) |
509 | BN_CTX_free(ctx); | 509 | goto err; |
510 | return -1; | 510 | if ((b3 = BN_CTX_get(ctx)) == NULL) |
511 | } | 511 | goto err; |
512 | |||
512 | /* | 513 | /* |
513 | * XXX This approach assumes that the external representation of | 514 | * XXX This approach assumes that the external representation of |
514 | * curves over the same field type is the same. | 515 | * curves over the same field type is the same. |
@@ -544,6 +545,12 @@ EC_GROUP_cmp(const EC_GROUP * a, const EC_GROUP * b, BN_CTX * ctx) | |||
544 | BN_CTX_free(ctx); | 545 | BN_CTX_free(ctx); |
545 | 546 | ||
546 | return r; | 547 | return r; |
548 | |||
549 | err: | ||
550 | BN_CTX_end(ctx); | ||
551 | if (ctx_new) | ||
552 | BN_CTX_free(ctx); | ||
553 | return -1; | ||
547 | } | 554 | } |
548 | 555 | ||
549 | 556 | ||