Skip to content

Commit

Permalink
Fix extra memory free for SEC1 EC key
Browse files Browse the repository at this point in the history
We should not free EC key in case of error in
`pk_parse_key_sec1_der` function, because it will
be freed later in `ttls_pk_free`.

Closes #1904
  • Loading branch information
EvgeniiMekhanik committed Jul 12, 2023
1 parent 872f58a commit 0d3a18b
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 14 deletions.
8 changes: 0 additions & 8 deletions tls/ecp.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,6 @@ ttls_ecp_keypair_init(TlsEcpKeypair *key)
ttls_ecp_point_init(&key->Q);
}

void
ttls_ecp_keypair_free(TlsEcpKeypair *key)
{
if (WARN_ON_ONCE(!key))
return;
ttls_mpi_pool_free(key);
}

void
ttls_ecp_copy(TlsEcpPoint *P, const TlsEcpPoint *Q)
{
Expand Down
1 change: 0 additions & 1 deletion tls/ecp.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ const TlsEcpCurveInfo *ttls_ecp_curve_info_from_tls_id(uint16_t tls_id);

void ttls_ecp_point_init(TlsEcpPoint *pt);
void ttls_ecp_keypair_init(TlsEcpKeypair *key);
void ttls_ecp_keypair_free(TlsEcpKeypair *key);

void ttls_ecp_copy(TlsEcpPoint *P, const TlsEcpPoint *Q);

Expand Down
5 changes: 0 additions & 5 deletions tls/pkparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -465,13 +465,9 @@ pk_parse_key_sec1_der(TlsEcpKeypair *eck, const unsigned char *key,
if (!r) {
if ((r = pk_get_ecparams(&p, p + len, &params))
|| (r = pk_use_ecparams(&params, &eck->grp)))
{
ttls_ecp_keypair_free(eck);
return r;
}
}
else if (r != TTLS_ERR_ASN1_UNEXPECTED_TAG) {
ttls_ecp_keypair_free(eck);
return TTLS_ERR_PK_KEY_INVALID_FORMAT + r;
}

Expand Down Expand Up @@ -505,7 +501,6 @@ pk_parse_key_sec1_der(TlsEcpKeypair *eck, const unsigned char *key,
}
}
else if (r != TTLS_ERR_ASN1_UNEXPECTED_TAG) {
ttls_ecp_keypair_free(eck);
return TTLS_ERR_PK_KEY_INVALID_FORMAT + r;
}
}
Expand Down

0 comments on commit 0d3a18b

Please sign in to comment.