Don't crash when failing to set affine coordinates when the generator is missing.
If a caller is in the process on constructing an arbitrary |EC_GROUP|,
and they try to create an |EC_POINT| to set as the generator which is
invalid, we would previously crash.
Change-Id: Ida91354257a02bd56ac29ba3104c9782b8d70f6b
Reviewed-on: https://boringssl-review.googlesource.com/25764
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
CQ-Verified: CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org>
diff --git a/crypto/fipsmodule/ec/ec.c b/crypto/fipsmodule/ec/ec.c
index 215acbb..904466a 100644
--- a/crypto/fipsmodule/ec/ec.c
+++ b/crypto/fipsmodule/ec/ec.c
@@ -770,7 +770,13 @@
if (!EC_POINT_is_on_curve(group, point, ctx)) {
// In the event of an error, defend against the caller not checking the
// return value by setting a known safe value: the base point.
- EC_POINT_copy(point, EC_GROUP_get0_generator(group));
+ const EC_POINT *generator = EC_GROUP_get0_generator(group);
+ // The generator can be missing if the caller is in the process of
+ // constructing an arbitrary group. In this, we give up and hope they're
+ // checking the return value.
+ if (generator) {
+ EC_POINT_copy(point, generator);
+ }
OPENSSL_PUT_ERROR(EC, EC_R_POINT_IS_NOT_ON_CURVE);
return 0;
}