Commit 40a8643a authored by Matt Caswell's avatar Matt Caswell
Browse files

Avoid a NULL ptr deref if group is not set



We should only copy parameters and keys if the group is set. Otherwise
they don't really make any sense. Previously we copied the private key
regardless of whether the group was set...but if it wasn't a NULL ptr
deref could occur. It's unclear whether we could ever get into that
situation, but since we were already checking it for the public key we
should be consistent.

Reviewed-by: default avatarRich Salz <rsalz@openssl.org>
parent 70015713
Loading
Loading
Loading
Loading
+21 −20
Original line number Diff line number Diff line
@@ -148,9 +148,9 @@ EC_KEY *EC_KEY_copy(EC_KEY *dest, EC_KEY *src)
            return NULL;
        if (!EC_GROUP_copy(dest->group, src->group))
            return NULL;
    }

        /*  copy the public key */
    if (src->pub_key != NULL && src->group != NULL) {
        if (src->pub_key != NULL) {
            EC_POINT_free(dest->pub_key);
            dest->pub_key = EC_POINT_new(src->group);
            if (dest->pub_key == NULL)
@@ -171,6 +171,7 @@ EC_KEY *EC_KEY_copy(EC_KEY *dest, EC_KEY *src)
                && src->group->meth->keycopy(dest, src) == 0)
                return NULL;
        }
    }


    /* copy the rest */