Skip to content

Commit acff29e

Browse files
committed
[NUC472/M487] Fix context clone corner case in SHA alter.
As destination/source contexts are the same, we return immediately.
1 parent d96bcda commit acff29e

File tree

5 files changed

+25
-0
lines changed

5 files changed

+25
-0
lines changed

features/mbedtls/targets/TARGET_NUVOTON/TARGET_M480/sha/sha1_alt.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ void mbedtls_sha1_free(mbedtls_sha1_context *ctx)
6363
void mbedtls_sha1_clone(mbedtls_sha1_context *dst,
6464
const mbedtls_sha1_context *src)
6565
{
66+
// Corner case: Destination/source contexts are the same
67+
if (dst == src) {
68+
return;
69+
}
70+
6671
// If dst is H/W context, we need to change it to S/W context first before cloning to.
6772
if (dst->active_ctx == &dst->hw_ctx) {
6873
mbedtls_sha1_free(dst);

features/mbedtls/targets/TARGET_NUVOTON/TARGET_M480/sha/sha256_alt.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ void mbedtls_sha256_free(mbedtls_sha256_context *ctx)
6363
void mbedtls_sha256_clone(mbedtls_sha256_context *dst,
6464
const mbedtls_sha256_context *src)
6565
{
66+
// Corner case: Destination/source contexts are the same
67+
if (dst == src) {
68+
return;
69+
}
70+
6671
// If dst is H/W context, we need to change it to S/W context first before cloning to.
6772
if (dst->active_ctx == &dst->hw_ctx) {
6873
mbedtls_sha256_free(dst);

features/mbedtls/targets/TARGET_NUVOTON/TARGET_M480/sha/sha512_alt.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ void mbedtls_sha512_free(mbedtls_sha512_context *ctx)
6363
void mbedtls_sha512_clone(mbedtls_sha512_context *dst,
6464
const mbedtls_sha512_context *src)
6565
{
66+
// Corner case: Destination/source contexts are the same
67+
if (dst == src) {
68+
return;
69+
}
70+
6671
// If dst is H/W context, we need to change it to S/W context first before cloning to.
6772
if (dst->active_ctx == &dst->hw_ctx) {
6873
mbedtls_sha512_free(dst);

features/mbedtls/targets/TARGET_NUVOTON/TARGET_NUC472/sha/sha1_alt.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ void mbedtls_sha1_free(mbedtls_sha1_context *ctx)
6363
void mbedtls_sha1_clone(mbedtls_sha1_context *dst,
6464
const mbedtls_sha1_context *src)
6565
{
66+
// Corner case: Destination/source contexts are the same
67+
if (dst == src) {
68+
return;
69+
}
70+
6671
// If dst is H/W context, we need to change it to S/W context first before cloning to.
6772
if (dst->active_ctx == &dst->hw_ctx) {
6873
mbedtls_sha1_free(dst);

features/mbedtls/targets/TARGET_NUVOTON/TARGET_NUC472/sha/sha256_alt.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ void mbedtls_sha256_free(mbedtls_sha256_context *ctx)
6363
void mbedtls_sha256_clone(mbedtls_sha256_context *dst,
6464
const mbedtls_sha256_context *src)
6565
{
66+
// Corner case: Destination/source contexts are the same
67+
if (dst == src) {
68+
return;
69+
}
70+
6671
// If dst is H/W context, we need to change it to S/W context first before cloning to.
6772
if (dst->active_ctx == &dst->hw_ctx) {
6873
mbedtls_sha256_free(dst);

0 commit comments

Comments
 (0)