Skip to content

Commit cd31838

Browse files
authored
Merge pull request #207 from miyazakh/fix_use_after_free
Fix use-after-free
2 parents 3369e9a + f40b585 commit cd31838

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

src/crypto/clu_evp_crypto.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ int wolfCLU_evp_crypto(const WOLFSSL_EVP_CIPHER* cphr, char* mode, byte* pwdKey,
4141
WOLFSSL_BIO *in = NULL;
4242
WOLFSSL_BIO *tmp = NULL;
4343
WOLFSSL_EVP_CIPHER_CTX* ctx = NULL;
44+
byte* decodedBase64 = NULL;
4445

4546
WC_RNG rng; /* random number generator declaration */
4647

@@ -74,7 +75,6 @@ int wolfCLU_evp_crypto(const WOLFSSL_EVP_CIPHER* cphr, char* mode, byte* pwdKey,
7475
if (fileIn != NULL) {
7576
in = wolfSSL_BIO_new_file(fileIn, "rb");
7677
if (in != NULL && !enc && isBase64) {
77-
byte *decodedBase64 = NULL;
7878
word32 decodeSz;
7979

8080
decodeSz = wolfSSL_BIO_get_len(in);
@@ -101,9 +101,6 @@ int wolfCLU_evp_crypto(const WOLFSSL_EVP_CIPHER* cphr, char* mode, byte* pwdKey,
101101
}
102102
}
103103

104-
if (decodedBase64 != NULL) {
105-
XFREE(decodedBase64, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
106-
}
107104
}
108105
}
109106
else {
@@ -398,6 +395,9 @@ int wolfCLU_evp_crypto(const WOLFSSL_EVP_CIPHER* cphr, char* mode, byte* pwdKey,
398395
wolfSSL_BIO_free(out);
399396
wolfSSL_BIO_free(in);
400397
wolfSSL_BIO_free(tmp);
398+
if (decodedBase64 != NULL) {
399+
XFREE(decodedBase64, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
400+
}
401401

402402
XMEMSET(key, 0, keySz);
403403
XMEMSET(iv, 0 , ivSz);

0 commit comments

Comments
 (0)