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
Commit-Queue: David Benjamin <>
Reviewed-by: David Benjamin <>
CQ-Verified: CQ bot account: <>
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);
+    }
     return 0;