From 8e36142250b078ab8347b1d0c40662ca5ae8d098 Mon Sep 17 00:00:00 2001 From: "Lucas, John P" Date: Wed, 26 Jul 2023 16:03:54 -0400 Subject: [PATCH] [nasa/cryptolib#189] Manually cherry pick merge onto KMC branch; --- .../cryptography_interface_libgcrypt.template.c | 2 +- src/src_main/crypto_tc.c | 12 ++++++------ util/src_util/standalone.c | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/src_cryptography/src_libgcrypt/cryptography_interface_libgcrypt.template.c b/src/src_cryptography/src_libgcrypt/cryptography_interface_libgcrypt.template.c index b1e7e0b3..60849e80 100644 --- a/src/src_cryptography/src_libgcrypt/cryptography_interface_libgcrypt.template.c +++ b/src/src_cryptography/src_libgcrypt/cryptography_interface_libgcrypt.template.c @@ -804,7 +804,7 @@ static int32_t cryptography_validate_authentication(uint8_t* data_out, size_t le printf("%02X", tmac[i]); } printf("\n"); - free(tmac); + if (!tmac) free(tmac); printf("Received MAC:\n\t"); for (uint32_t i = 0; i < mac_size; i ++){ diff --git a/src/src_main/crypto_tc.c b/src/src_main/crypto_tc.c index 6c243d51..3c3dc641 100644 --- a/src/src_main/crypto_tc.c +++ b/src/src_main/crypto_tc.c @@ -662,7 +662,7 @@ int32_t Crypto_TC_ApplySecurity_Cam(const uint8_t* p_in_frame, const uint16_t in } if (status != CRYPTO_LIB_SUCCESS) { - free(aad); + if (!aad) free (aad); return status; // Cryptography IF call failed, return. } } @@ -752,7 +752,7 @@ int32_t Crypto_TC_ApplySecurity_Cam(const uint8_t* p_in_frame, const uint16_t in #ifdef DEBUG printf(KYEL "----- Crypto_TC_ApplySecurity END -----\n" RESET); #endif - free(aad); + if (!aad) free (aad); return status; } @@ -1148,7 +1148,7 @@ int32_t Crypto_TC_ProcessSecurity_Cam(uint8_t* ingest, int *len_ingest, TC_t* tc if (status != CRYPTO_LIB_SUCCESS) { - free(aad); + if (!aad) free (aad); return status; // Cryptography IF call failed, return. } @@ -1159,7 +1159,7 @@ int32_t Crypto_TC_ProcessSecurity_Cam(uint8_t* ingest, int *len_ingest, TC_t* tc if(status != CRYPTO_LIB_SUCCESS) { - free(aad); + if (!aad) free (aad); return status; } @@ -1167,7 +1167,7 @@ int32_t Crypto_TC_ProcessSecurity_Cam(uint8_t* ingest, int *len_ingest, TC_t* tc status = sadb_routine->sadb_save_sa(sa_ptr); if(status != CRYPTO_LIB_SUCCESS) { - free(aad); + if (!aad) free (aad); return status; } } @@ -1190,7 +1190,7 @@ int32_t Crypto_TC_ProcessSecurity_Cam(uint8_t* ingest, int *len_ingest, TC_t* tc { status = Crypto_Process_Extended_Procedure_Pdu(tc_sdls_processed_frame, ingest); } - free(aad); + if (!aad) free (aad); return status; } diff --git a/util/src_util/standalone.c b/util/src_util/standalone.c index 0e5c0573..51e4b3e1 100644 --- a/util/src_util/standalone.c +++ b/util/src_util/standalone.c @@ -341,7 +341,7 @@ void* crypto_standalone_tc_apply(void* sock) memset(tc_apply_in, 0x00, sizeof(tc_apply_in)); tc_in_len = 0; tc_out_len = 0; - free(tc_out_ptr); + if (!tc_out_ptr) free(tc_out_ptr); #ifdef CRYPTO_STANDALONE_TC_APPLY_DEBUG printf("\n"); #endif