Skip to content

Commit

Permalink
Merge pull request #193 from nasa/189-free-ptr-checks
Browse files Browse the repository at this point in the history
Null checks on ptr frees;
  • Loading branch information
dccutrig committed Jul 26, 2023
2 parents 7b8637e + 2e3b2be commit dfe5643
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
26 changes: 13 additions & 13 deletions src/core/crypto_tc.c
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ int32_t Crypto_TC_ApplySecurity_Cam(const uint8_t* p_in_frame, const uint16_t in
// Check that key length to be used ets the algorithm requirement
if ((int32_t)ekp->key_len != Crypto_Get_ECS_Algo_Keylen(sa_ptr->ecs))
{
free(aad);
if (!aad) free(aad);
status = CRYPTO_LIB_ERR_KEY_LENGTH_ERROR;
mc_if->mc_log(status);
return status;
Expand Down Expand Up @@ -637,7 +637,7 @@ int32_t Crypto_TC_ApplySecurity_Cam(const uint8_t* p_in_frame, const uint16_t in
// Check that key length to be used ets the algorithm requirement
if ((int32_t)ekp->key_len != Crypto_Get_ECS_Algo_Keylen(sa_ptr->ecs))
{
free(aad);
if (!aad) free(aad);
return CRYPTO_LIB_ERR_KEY_LENGTH_ERROR;
}

Expand Down Expand Up @@ -670,7 +670,7 @@ int32_t Crypto_TC_ApplySecurity_Cam(const uint8_t* p_in_frame, const uint16_t in
// Check that key length to be used ets the algorithm requirement
if ((int32_t)akp->key_len != Crypto_Get_ACS_Algo_Keylen(sa_ptr->acs))
{
free(aad);
if (!aad) free(aad);
return CRYPTO_LIB_ERR_KEY_LENGTH_ERROR;
}

Expand All @@ -694,7 +694,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);
mc_if->mc_log(status);
return status; // Cryptography IF call failed, return.
}
Expand Down Expand Up @@ -794,7 +794,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);
mc_if->mc_log(status);
return status;
}
Expand Down Expand Up @@ -1143,7 +1143,7 @@ int32_t Crypto_TC_ProcessSecurity_Cam(uint8_t* ingest, int* len_ingest, TC_t* tc
// Check that key length to be used ets the algorithm requirement
if ((int32_t)ekp->key_len != Crypto_Get_ECS_Algo_Keylen(sa_ptr->ecs))
{
free(aad);
if (!aad) free(aad);
status = CRYPTO_LIB_ERR_KEY_LENGTH_ERROR;
mc_if->mc_log(status);
return status;
Expand Down Expand Up @@ -1179,7 +1179,7 @@ int32_t Crypto_TC_ProcessSecurity_Cam(uint8_t* ingest, int* len_ingest, TC_t* tc
// Check that key length to be used ets the algorithm requirement
if ((int32_t)akp->key_len != Crypto_Get_ACS_Algo_Keylen(sa_ptr->acs))
{
free(aad);
if (!aad) free(aad);
status = CRYPTO_LIB_ERR_KEY_LENGTH_ERROR;
mc_if->mc_log(status);
return status;
Expand Down Expand Up @@ -1207,7 +1207,7 @@ int32_t Crypto_TC_ProcessSecurity_Cam(uint8_t* ingest, int* len_ingest, TC_t* tc
// Check that key length to be used emets the algorithm requirement
if ((int32_t)ekp->key_len != Crypto_Get_ECS_Algo_Keylen(sa_ptr->ecs))
{
free(aad);
if (!aad) free(aad);
status = CRYPTO_LIB_ERR_KEY_LENGTH_ERROR;
mc_if->mc_log(status);
return status;
Expand Down Expand Up @@ -1249,7 +1249,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);
mc_if->mc_log(status);
return status; // Cryptography IF call failed, return.
}
Expand All @@ -1261,7 +1261,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);
mc_if->mc_log(status);
return status;
}
Expand All @@ -1270,7 +1270,7 @@ int32_t Crypto_TC_ProcessSecurity_Cam(uint8_t* ingest, int* len_ingest, TC_t* tc
status = sa_if->sa_save_sa(sa_ptr);
if (status != CRYPTO_LIB_SUCCESS)
{
free(aad);
if (!aad) free(aad);
mc_if->mc_log(status);
return status;
}
Expand All @@ -1290,7 +1290,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);
mc_if->mc_log(status);
return status;
}
Expand Down Expand Up @@ -1445,6 +1445,6 @@ static int32_t crypto_handle_incrementing_nontransmitted_counter(uint8_t* dest,
{
status = CRYPTO_LIB_ERR_FRAME_COUNTER_DOESNT_MATCH_SA;
}
free(temp_counter);
if (!temp_counter) free(temp_counter);
return status;
}
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,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 ++){
Expand Down
2 changes: 1 addition & 1 deletion support/standalone/standalone.c
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,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);
if (tc_debug == 1)
{
printf("\n");
Expand Down

0 comments on commit dfe5643

Please sign in to comment.