Skip to content

[noup] zephyr: crypto: fix coverity issue #87

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions src/crypto/crypto_mbedtls_alt.c
Original file line number Diff line number Diff line change
Expand Up @@ -1927,6 +1927,8 @@ struct wpabuf *crypto_ecdh_set_peerkey(struct crypto_ecdh *ecdh, int inc_y, cons
}
else if (key[0] == 0x02 || key[0] == 0x03)
{ /* (inc_y == 0) */
if(len == 0)
return NULL;
--len; /*(repurpose len to prime_len)*/

/* mbedtls_ecp_point_read_binary() does not currently support
Expand Down Expand Up @@ -2643,6 +2645,7 @@ struct wpabuf *crypto_ec_key_get_subject_public_key(struct crypto_ec_key *key)
/* algorithm AlgorithmIdentifier */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and the other
[noup] zephyr: crypto: Fix coverity issue when getting public/private key

unsigned char *a = p;
size_t alen;
int ret;
mbedtls_asn1_get_tag(&p, end, &alen, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE);
p += alen;
alen = (size_t)(p - a);
Expand All @@ -2656,8 +2659,16 @@ struct wpabuf *crypto_ec_key_get_subject_public_key(struct crypto_ec_key *key)
os_memmove(p - alen, a, alen);
len += alen;
p -= alen;
len += mbedtls_asn1_write_len(&p, buf, (size_t)len);
len += mbedtls_asn1_write_tag(&p, buf, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE);
if ((ret = mbedtls_asn1_write_len(&p, buf, (size_t)len)) < 0)
{
return NULL;
}
len += ret;
if ((ret = mbedtls_asn1_write_tag(&p, buf, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) < 0)
{
return NULL;
}
len += ret;
}
#endif
return wpabuf_alloc_copy(p, (size_t)len);
Expand Down Expand Up @@ -2688,6 +2699,7 @@ struct wpabuf *crypto_ec_key_get_ecprivate_key(struct crypto_ec_key *key, bool i
unsigned char *p = priv + sizeof(priv) - privlen;
unsigned char *end = priv + sizeof(priv);
size_t len;
int ret;
/* ECPrivateKey SEQUENCE */
mbedtls_asn1_get_tag(&p, end, &len, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE);
/* version INTEGER */
Expand All @@ -2704,8 +2716,16 @@ struct wpabuf *crypto_ec_key_get_ecprivate_key(struct crypto_ec_key *key, bool i
/* write new SEQUENCE header (we know that it fits in priv[]) */
len = (size_t)(p - v);
p = v;
len += mbedtls_asn1_write_len(&p, priv, len);
len += mbedtls_asn1_write_tag(&p, priv, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE);
if ((ret = mbedtls_asn1_write_len(&p, priv, len)) < 0)
{
return NULL;
}
len += ret;
if ((ret = mbedtls_asn1_write_tag(&p, priv, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) < 0)
{
return NULL;
}
len += ret;
wbuf = wpabuf_alloc_copy(p, len);
}

Expand Down