Skip to content

Commit 7dd83b7

Browse files
committed
Fix TI hashCopy to copy accumulated message buffer (F-2646)
1 parent 1cfa98a commit 7dd83b7

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

wolfcrypt/src/port/ti/ti-hash.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,19 @@ static int hashCopy(wolfssl_TI_Hash *src, wolfssl_TI_Hash *dst)
127127
{
128128
if (src == NULL || dst == NULL)
129129
return BAD_FUNC_ARG;
130-
/* only copy hash, zero the rest of the struct to avoid double-free */
131-
dst->msg = NULL;
132-
dst->used = 0;
133-
dst->len = 0;
130+
/* copy the accumulated message into a fresh buffer so each descriptor
131+
* owns its own allocation and can be freed independently */
132+
dst->used = src->used;
133+
dst->len = src->len;
134+
if ((src->msg != NULL) && (src->len > 0)) {
135+
dst->msg = (byte*)XMALLOC(src->len, NULL, DYNAMIC_TYPE_TMP_BUFFER);
136+
if (dst->msg == NULL)
137+
return MEMORY_E;
138+
XMEMCPY(dst->msg, src->msg, src->len);
139+
}
140+
else {
141+
dst->msg = NULL;
142+
}
134143
XMEMCPY(dst->hash, src->hash, sizeof(dst->hash));
135144
return 0;
136145
}

0 commit comments

Comments
 (0)