From 30e787b10c8394bf50697d8586a0b2efc3d92dd9 Mon Sep 17 00:00:00 2001 From: Jacob Barthelmeh Date: Fri, 3 Aug 2018 16:46:15 -0600 Subject: [PATCH] create buffer with structure copy and set fd after close --- wolfcrypt/src/port/af_alg/afalg_hash.c | 10 ++++++++++ wolfcrypt/src/sha256.c | 2 ++ 2 files changed, 12 insertions(+) diff --git a/wolfcrypt/src/port/af_alg/afalg_hash.c b/wolfcrypt/src/port/af_alg/afalg_hash.c index 57c6ad0b0..f355f61c3 100644 --- a/wolfcrypt/src/port/af_alg/afalg_hash.c +++ b/wolfcrypt/src/port/af_alg/afalg_hash.c @@ -176,10 +176,20 @@ int wc_Sha256Copy(wc_Sha256* src, wc_Sha256* dst) } XMEMCPY(dst, src, sizeof(wc_Sha256)); + +#ifdef WOLFSSL_AFALG_HASH_KEEP + dst->msg = (byte*)XMALLOC(src->len, dst->heap, DYNAMIC_TYPE_TMP_BUFFER); + if (dst->msg == NULL) { + return MEMORY_E; + } + XMEMCPY(dst->msg, src->msg, src->len); +#endif + dst->rdFd = accept(src->rdFd, NULL, 0); dst->alFd = accept(src->alFd, NULL, 0); if (dst->rdFd == -1 || dst->alFd == -1) { + wc_Sha256Free(dst); return -1; } diff --git a/wolfcrypt/src/sha256.c b/wolfcrypt/src/sha256.c index a2d822bf9..7e4ae2314 100644 --- a/wolfcrypt/src/sha256.c +++ b/wolfcrypt/src/sha256.c @@ -2750,9 +2750,11 @@ void wc_Sha256Free(wc_Sha256* sha256) #if defined(WOLFSSL_AFALG_HASH) if (sha256->alFd > 0) { close(sha256->alFd); + sha256->alFd = -1; /* avoid possible double close on socket */ } if (sha256->rdFd > 0) { close(sha256->rdFd); + sha256->rdFd = -1; /* avoid possible double close on socket */ } #if defined(WOLFSSL_AFALG_HASH_KEEP)