From a8c24756c08b7f41ce757b2c7a9dc7b39b3cb563 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 24 Dec 2021 11:28:26 +0100 Subject: Fix libkeccak_state_copy MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- libkeccak_state_copy.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/libkeccak_state_copy.c b/libkeccak_state_copy.c index 97a76ef..bf82fa9 100644 --- a/libkeccak_state_copy.c +++ b/libkeccak_state_copy.c @@ -13,9 +13,13 @@ int libkeccak_state_copy(struct libkeccak_state *restrict dest, const struct libkeccak_state *restrict src) { memcpy(dest, src, sizeof(struct libkeccak_state)); - dest->M = malloc(src->mlen * sizeof(char)); - if (!dest->M) - return -1; - memcpy(dest->M, src->M, src->mptr * sizeof(char)); + if (src->mlen) { + dest->M = malloc(src->mlen * sizeof(char)); + if (!dest->M) + return -1; + memcpy(dest->M, src->M, src->mptr * sizeof(char)); + } else { + dest->M = NULL; + } return 0; } -- cgit v1.2.3-70-g09d2