diff --git a/docs/api/10-bsl-developers.md b/docs/api/10-bsl-developers.md index 373a8fe..38228a7 100644 --- a/docs/api/10-bsl-developers.md +++ b/docs/api/10-bsl-developers.md @@ -209,17 +209,20 @@ After its de-initialization the members of the struct will no longer have well d To help with troubleshooting, de-initialization should set pointers set to NULL and other values to a well-defined state. One option is to use `memset()` to zeroize the entire struct. -# Macros +## Memory Management Functions -This section contains references to commonly used macros defined for the BSL +When heap memory is needed at BSL runtime, the following functions are used and have the same signature and semantics as the corresponding C99 functions indicated below. -## Memory Management Macros +- [BSL_malloc](@ref BSL_malloc) as `malloc()` +- [BSL_realloc](@ref BSL_realloc) as `realloc()` +- [BSL_calloc](@ref BSL_calloc) as `calloc()` +- [BSL_free](@ref BSL_free) as `free()` -When heap memory is needed at BSL runtime, the following macros are used and have the same signature and semantics as the corresponding C99 functions indicated below. +These can be modified using the @ref BSL_DynMemHostDescriptors_t interface. -- [BSL_MALLOC](@ref BSL_MALLOC) as `malloc()` -- [BSL_REALLOC](@ref BSL_REALLOC) as `realloc()` -- [BSL_FREE](@ref BSL_FREE) as `free()` +# Macros + +This section contains references to commonly used macros defined for the BSL ## Error Checking Handler Macros diff --git a/docs/api/dictionary.txt b/docs/api/dictionary.txt index 6c4a486..a12897b 100644 --- a/docs/api/dictionary.txt +++ b/docs/api/dictionary.txt @@ -123,6 +123,7 @@ JSON JWK KEK len +libc LibCtx lifecycle Lifecycles diff --git a/src/BPSecLib_Private.h b/src/BPSecLib_Private.h index 4107f51..ff62529 100644 --- a/src/BPSecLib_Private.h +++ b/src/BPSecLib_Private.h @@ -425,6 +425,27 @@ int BSL_HostEIDPattern_DecodeFromText(BSL_HostEIDPattern_t *pat, const char *tex */ bool BSL_HostEIDPattern_IsMatch(const BSL_HostEIDPattern_t *pat, const BSL_HostEID_t *eid); +/// @brief Dynamic memory allocation +/// @param size size of allocation +/// @return valid heap pointer +void *BSL_malloc(size_t size); + +/// @brief Dynamic memory reallocation +/// @param ptr existing dynamic memory pointer +/// @param size new allocation size +/// @return valid heap pointer +void *BSL_realloc(void *ptr, size_t size); + +/// @brief Contiguous dynamic memory allocation +/// @param nmemb number of members to allocate +/// @param size size of each member +/// @return valid heap pointer +void *BSL_calloc(size_t nmemb, size_t size); + +/// @brief Free dynamically allocated memory +/// @param ptr pointer to memory to free +void BSL_free(void *ptr); + /** Block types using IANA-assigned code points from @cite iana:bundle. */ typedef enum diff --git a/src/BPSecLib_Public.h b/src/BPSecLib_Public.h index a439ba2..698141f 100644 --- a/src/BPSecLib_Public.h +++ b/src/BPSecLib_Public.h @@ -260,6 +260,42 @@ typedef struct BSL_CanonicalBlock_s size_t btsd_len; ///< Length in bytes of the BTSD accessible through sequential APIs } BSL_CanonicalBlock_t; +/** Dynamic memory callback descriptors used by Dynamic BPA descriptor. + * + * These are meant to be used as part of ::BSL_HostDescriptors_t for + * registering host callbacks. + */ +typedef struct +{ + /** Dynamic memory allocation callback. + * + * @return valid heap pointer on success, NULL on failure. + */ + void *(*malloc_cb)(size_t size); + + /** Dynamic memory re-allocation callback. + * + * @return valid heap pointer on success, NULL on failure. + */ + void *(*realloc_cb)(void *ptr, size_t size); + + /** Contiguous dynamic memory allocation callback. + * + * @return valid 0-initialized heap pointer on success, NULL on failure. + */ + void *(*calloc_cb)(size_t nmemb, size_t size); + + /** Free dynamic memory allocation callback. + */ + void (*free_cb)(void *ptr); +} BSL_DynMemHostDescriptors_t; + +/// Default heap functions from libc +#define BSL_DynMemHostDescriptors_DEFAULT \ + { \ + .malloc_cb = malloc, .realloc_cb = realloc, .calloc_cb = calloc, .free_cb = free, \ + } + /** Dynamic BPA descriptor. */ typedef struct @@ -350,6 +386,10 @@ typedef struct /// @brief Host BPA function that returns true if the given EID matched an EID pattern. bool (*eidpat_match)(const BSL_HostEIDPattern_t *pat, const BSL_HostEID_t *eid, void *user_data); + + /// @brief Optionally set dynamic memory management callbacks. Defaults to libc calls if unset. + BSL_DynMemHostDescriptors_t dyn_mem_desc; + } BSL_HostDescriptors_t; /** Set the BPA descriptor (callbacks) for this process. diff --git a/src/BSLConfig.h.in b/src/BSLConfig.h.in index 0bdb33c..9ddb35f 100644 --- a/src/BSLConfig.h.in +++ b/src/BSLConfig.h.in @@ -53,30 +53,6 @@ extern "C" { */ const char * bsl_version(void); -#ifndef BSL_MALLOC -/** Uses the same function signature as C99 malloc(). - */ -#define BSL_MALLOC malloc -#endif /* BSL_MALLOC */ - -#ifndef BSL_REALLOC -/** Uses the same function signature as C99 realloc(). - */ -#define BSL_REALLOC realloc -#endif /* BSL_REALLOC */ - -#ifndef BSL_FREE -/** Uses the same function signature as C99 free(). - */ -#define BSL_FREE free -#endif /* BSL_FREE */ - -#ifndef BSL_CALLOC -/** Uses the same function signature as C99 calloc(). - */ -#define BSL_CALLOC calloc -#endif /* BSL_CALLOC */ - /** Force the use of M_ prefixed macros for M*LIB */ //#define M_USE_SMALL_NAME 0 @@ -85,25 +61,25 @@ const char * bsl_version(void); /** Define to override value/struct allocation. * See m-core.h for details. */ -#define M_MEMORY_ALLOC(type) ((type *) BSL_MALLOC(sizeof(type))) +#define M_MEMORY_ALLOC(type) ((type *) BSL_malloc(sizeof(type))) #undef M_MEMORY_DEL /** Define to override value/struct deallocation. * See m-core.h for details. */ -#define M_MEMORY_DEL(ptr) BSL_FREE(ptr) +#define M_MEMORY_DEL(ptr) BSL_free(ptr) #undef M_MEMORY_REALLOC /** Define to override array allocation. * See m-core.h for details. */ -#define M_MEMORY_REALLOC(type, ptr, n) (M_UNLIKELY((n) > SIZE_MAX / sizeof(type)) ? (type *) NULL : (type *) BSL_REALLOC((ptr), (n)*sizeof (type))) +#define M_MEMORY_REALLOC(type, ptr, n) (M_UNLIKELY((n) > SIZE_MAX / sizeof(type)) ? (type *) NULL : (type *) BSL_realloc((ptr), (n)*sizeof (type))) #undef M_MEMORY_FREE /** Define to override array deallocation. * See m-core.h for details. */ -#define M_MEMORY_FREE(ptr) BSL_FREE(ptr) +#define M_MEMORY_FREE(ptr) BSL_free(ptr) #ifdef __cplusplus } // extern C diff --git a/src/CryptoInterface.h b/src/CryptoInterface.h index 7bbd142..8468b9d 100644 --- a/src/CryptoInterface.h +++ b/src/CryptoInterface.h @@ -215,7 +215,7 @@ int BSL_AuthCtx_Deinit(BSL_AuthCtx_t *hmac_ctx); /** * Deinit and free generated key handle * @param[in] keyhandle key handle to clear. - * Key handle assumed to be generated, not present in key registry, and allocated with ::BSL_MALLOC(). + * Key handle assumed to be generated, not present in key registry, and allocated with ::BSL_malloc(). * @returns 0 if successfully cleared key handle */ int BSL_Crypto_ClearGeneratedKeyHandle(void *keyhandle); @@ -226,7 +226,7 @@ int BSL_Crypto_ClearGeneratedKeyHandle(void *keyhandle); * @param[in] kek_handle key encryption key handle (encryption key) * @param[in] cek_handle content encryption key handle (encryption data) * @param[in,out] wrapped_key output wrapped key (ciphertext) bytes - * @param[in,out] wrapped_key_handle output wrapped key (ciphertext) handle, allocated with ::BSL_MALLOC(). Set to NULL + * @param[in,out] wrapped_key_handle output wrapped key (ciphertext) handle, allocated with ::BSL_malloc(). Set to NULL * if handle not needed. */ int BSL_Crypto_WrapKey(void *kek_handle, void *cek_handle, BSL_Data_t *wrapped_key, void **wrapped_key_handle); @@ -236,7 +236,7 @@ int BSL_Crypto_WrapKey(void *kek_handle, void *cek_handle, BSL_Data_t *wrapped_k * CEK size expected to match size of KEK * @param[in] kek_handle key encryption key handle (decryption key) * @param[in] wrapped_key input wrapped key (ciphertext) bytes - * @param[in,out] cek_handle output content encryption key (plaintext) handle, allocated with ::BSL_MALLOC() + * @param[in,out] cek_handle output content encryption key (plaintext) handle, allocated with ::BSL_malloc() */ int BSL_Crypto_UnwrapKey(void *kek_handle, BSL_Data_t *wrapped_key, void **cek_handle); @@ -326,7 +326,7 @@ int BSL_Cipher_Deinit(BSL_Cipher_t *cipher_ctx); /** * Generate a new cryptographic key * @param[in] key_length length of new key. Should be 16 or 32 - * @param[in, out] key_out pointer to pointer for new key handle, allocated with ::BSL_MALLOC() + * @param[in, out] key_out pointer to pointer for new key handle, allocated with ::BSL_malloc() */ int BSL_Crypto_GenKey(size_t key_length, void **key_out); diff --git a/src/Data.c b/src/Data.c index b477615..a3ee267 100644 --- a/src/Data.c +++ b/src/Data.c @@ -42,7 +42,7 @@ static void bsl_data_int_free(BSL_Data_t *data) if (data->owned && data->ptr) { - BSL_FREE(data->ptr); + BSL_free(data->ptr); } } @@ -59,7 +59,7 @@ int BSL_Data_InitBuffer(BSL_Data_t *data, size_t bytelen) CHK_ARG_EXPR(bytelen > 0); bsl_data_int_reset(data); - data->ptr = BSL_MALLOC(bytelen); + data->ptr = BSL_malloc(bytelen); data->len = bytelen; data->owned = true; memset(data->ptr, 0, bytelen); @@ -145,7 +145,7 @@ int BSL_Data_Resize(BSL_Data_t *data, size_t len) { data->ptr = NULL; } - BSL_DataPtr_t got = BSL_REALLOC(data->ptr, len); + BSL_DataPtr_t got = BSL_realloc(data->ptr, len); if (UNLIKELY(!got)) { bsl_data_int_reset(data); diff --git a/src/backend/HostInterface.c b/src/backend/HostInterface.c index 3c9c8e2..aceb5d3 100644 --- a/src/backend/HostInterface.c +++ b/src/backend/HostInterface.c @@ -27,7 +27,8 @@ #include "UtilDefs_SeqReadWrite.h" // NOLINTNEXTLINE -static BSL_HostDescriptors_t HostDescriptorTable = { 0 }; +/// Initialized to library default +static BSL_HostDescriptors_t HostDescriptorTable = { .dyn_mem_desc = BSL_DynMemHostDescriptors_DEFAULT }; int BSL_HostDescriptors_Set(BSL_HostDescriptors_t desc) { @@ -48,6 +49,19 @@ int BSL_HostDescriptors_Set(BSL_HostDescriptors_t desc) CHK_PRECONDITION(desc.eidpat_deinit); CHK_PRECONDITION(desc.eidpat_from_text); CHK_PRECONDITION(desc.eidpat_match); + + // If all callbacks are unset/NULL, use default + if (NULL == desc.dyn_mem_desc.malloc_cb && NULL == desc.dyn_mem_desc.realloc_cb + && NULL == desc.dyn_mem_desc.calloc_cb && NULL == desc.dyn_mem_desc.free_cb) + { + desc.dyn_mem_desc = (BSL_DynMemHostDescriptors_t)BSL_DynMemHostDescriptors_DEFAULT; + } + // otherwiese, if any one are unset, return error + else if (NULL == desc.dyn_mem_desc.malloc_cb || NULL == desc.dyn_mem_desc.realloc_cb + || NULL == desc.dyn_mem_desc.calloc_cb || NULL == desc.dyn_mem_desc.free_cb) + { + return BSL_ERR_ARG_NULL; + } // GCOV_EXCL_STOP HostDescriptorTable = desc; @@ -224,3 +238,23 @@ bool BSL_HostEIDPattern_IsMatch(const BSL_HostEIDPattern_t *pat, const BSL_HostE ASSERT_PRECONDITION(HostDescriptorTable.eidpat_match); return HostDescriptorTable.eidpat_match(pat, eid, HostDescriptorTable.user_data); } + +void *BSL_malloc(size_t size) +{ + return HostDescriptorTable.dyn_mem_desc.malloc_cb(size); +} + +void *BSL_realloc(void *ptr, size_t size) +{ + return HostDescriptorTable.dyn_mem_desc.realloc_cb(ptr, size); +} + +void *BSL_calloc(size_t nmemb, size_t size) +{ + return HostDescriptorTable.dyn_mem_desc.calloc_cb(nmemb, size); +} + +void BSL_free(void *ptr) +{ + HostDescriptorTable.dyn_mem_desc.free_cb(ptr); +} diff --git a/src/backend/PublicInterfaceImpl.c b/src/backend/PublicInterfaceImpl.c index 43dddb0..3588eb5 100644 --- a/src/backend/PublicInterfaceImpl.c +++ b/src/backend/PublicInterfaceImpl.c @@ -91,7 +91,7 @@ void BSL_PrimaryBlock_deinit(BSL_PrimaryBlock_t *obj) { ASSERT_ARG_NONNULL(obj); - BSL_FREE(obj->block_numbers); + BSL_free(obj->block_numbers); obj->block_numbers = NULL; BSL_Data_Deinit(&obj->encoded); @@ -174,7 +174,7 @@ int BSL_API_QuerySecurity(const BSL_LibCtx_t *bsl, BSL_SecurityActionSet_t *outp BSL_SeqReader_Get(btsd_read, btsd_copy.ptr, &btsd_copy.len); BSL_SeqReader_Destroy(btsd_read); - BSL_AbsSecBlock_t *abs_sec_block = BSL_CALLOC(1, BSL_AbsSecBlock_Sizeof()); + BSL_AbsSecBlock_t *abs_sec_block = BSL_calloc(1, BSL_AbsSecBlock_Sizeof()); BSL_AbsSecBlock_InitEmpty(abs_sec_block); if (BSL_AbsSecBlock_DecodeFromCBOR(abs_sec_block, &btsd_copy) == 0) { @@ -189,7 +189,7 @@ int BSL_API_QuerySecurity(const BSL_LibCtx_t *bsl, BSL_SecurityActionSet_t *outp BSL_SecOper_SetReasonCode(sec_oper, BSL_REASONCODE_BLOCK_UNINTELLIGIBLE); } BSL_AbsSecBlock_Deinit(abs_sec_block); - BSL_FREE(abs_sec_block); + BSL_free(abs_sec_block); BSL_Data_Deinit(&btsd_copy); } diff --git a/src/backend/SecurityContext.c b/src/backend/SecurityContext.c index 0b9324e..572d8a0 100644 --- a/src/backend/SecurityContext.c +++ b/src/backend/SecurityContext.c @@ -481,7 +481,7 @@ int BSL_SecCtx_ExecutePolicyActionSet(BSL_LibCtx_t *lib, BSL_SecurityResponseSet * - BCB will be a special case, since it actively manipulates the BTSD * */ - BSL_SecOutcome_t *outcome = BSL_CALLOC(1, BSL_SecOutcome_Sizeof()); + BSL_SecOutcome_t *outcome = BSL_calloc(1, BSL_SecOutcome_Sizeof()); BSL_SecActionList_it_t act_it; for (BSL_SecActionList_it(act_it, action_set->actions); !BSL_SecActionList_end_p(act_it); @@ -535,7 +535,7 @@ int BSL_SecCtx_ExecutePolicyActionSet(BSL_LibCtx_t *lib, BSL_SecurityResponseSet BSL_SecurityResponseSet_AppendResult(output_response, errcode, sec_oper->policy_action); } } - BSL_FREE(outcome); + BSL_free(outcome); return BSL_SUCCESS; } diff --git a/src/backend/UtilDefs_SeqReadWrite.c b/src/backend/UtilDefs_SeqReadWrite.c index 278a79d..3ccfe71 100644 --- a/src/backend/UtilDefs_SeqReadWrite.c +++ b/src/backend/UtilDefs_SeqReadWrite.c @@ -39,7 +39,7 @@ int BSL_SeqReader_Destroy(BSL_SeqReader_t *obj) CHK_ARG_NONNULL(obj->deinit); obj->deinit(obj->user_data); - BSL_FREE(obj); + BSL_free(obj); return BSL_SUCCESS; } @@ -59,7 +59,7 @@ int BSL_SeqWriter_Destroy(BSL_SeqWriter_t *obj) CHK_ARG_NONNULL(obj->deinit); obj->deinit(obj->user_data); - BSL_FREE(obj); + BSL_free(obj); return BSL_SUCCESS; } diff --git a/src/crypto/CryptoInterface.c b/src/crypto/CryptoInterface.c index e6a102b..0afe521 100644 --- a/src/crypto/CryptoInterface.c +++ b/src/crypto/CryptoInterface.c @@ -124,7 +124,7 @@ int BSL_Crypto_ClearGeneratedKeyHandle(void *keyhandle) BSL_CryptoKey_t *key = (BSL_CryptoKey_t *)keyhandle; BSL_CryptoKey_Deinit(key); - BSL_FREE(key); + BSL_free(key); return BSL_SUCCESS; } @@ -164,7 +164,7 @@ int BSL_Crypto_UnwrapKey(void *kek_handle, BSL_Data_t *wrapped_key, void **cek_h return BSL_ERR_SECURITY_CONTEXT_CRYPTO_FAILED; } - BSL_CryptoKey_t *cek = BSL_MALLOC(sizeof(BSL_CryptoKey_t)); + BSL_CryptoKey_t *cek = BSL_malloc(sizeof(BSL_CryptoKey_t)); if (cek == NULL) { return BSL_ERR_SECURITY_CONTEXT_CRYPTO_FAILED; @@ -180,7 +180,7 @@ int BSL_Crypto_UnwrapKey(void *kek_handle, BSL_Data_t *wrapped_key, void **cek_h if (dec_result != 1) { BSL_CryptoKey_Deinit(cek); - BSL_FREE(cek); + BSL_free(cek); return BSL_ERR_SECURITY_CONTEXT_CRYPTO_FAILED; } EVP_CIPHER_CTX_set_padding(ctx, 0); @@ -193,7 +193,7 @@ int BSL_Crypto_UnwrapKey(void *kek_handle, BSL_Data_t *wrapped_key, void **cek_h BSL_LOG_ERR("EVP_DecryptUpdate: %s", ERR_error_string(ERR_get_error(), NULL)); EVP_CIPHER_CTX_free(ctx); BSL_CryptoKey_Deinit(cek); - BSL_FREE(cek); + BSL_free(cek); return BSL_ERR_SECURITY_CONTEXT_CRYPTO_FAILED; } @@ -207,7 +207,7 @@ int BSL_Crypto_UnwrapKey(void *kek_handle, BSL_Data_t *wrapped_key, void **cek_h BSL_LOG_ERR("Failed DecryptFinal: %s", ERR_error_string(ERR_get_error(), NULL)); EVP_CIPHER_CTX_free(ctx); BSL_CryptoKey_Deinit(cek); - BSL_FREE(cek); + BSL_free(cek); return BSL_ERR_SECURITY_CONTEXT_CRYPTO_FAILED; } @@ -223,7 +223,7 @@ int BSL_Crypto_UnwrapKey(void *kek_handle, BSL_Data_t *wrapped_key, void **cek_h if (res != 1) { BSL_CryptoKey_Deinit(cek); - BSL_FREE(cek); + BSL_free(cek); return BSL_ERR_SECURITY_CONTEXT_CRYPTO_FAILED; } @@ -322,7 +322,7 @@ int BSL_Crypto_WrapKey(void *kek_handle, void *cek_handle, BSL_Data_t *wrapped_k int res = EVP_PKEY_keygen_init(pctx); CHK_PROPERTY(res == 1); - BSL_CryptoKey_t *new_wrapped_key_handle = BSL_MALLOC(sizeof(BSL_CryptoKey_t)); + BSL_CryptoKey_t *new_wrapped_key_handle = BSL_malloc(sizeof(BSL_CryptoKey_t)); BSL_CryptoKey_Init(new_wrapped_key_handle); new_wrapped_key_handle->pkey = EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL, wrapped_key->ptr, wrapped_key->len); BSL_Data_Init(&new_wrapped_key_handle->raw); @@ -630,7 +630,7 @@ int BSL_Crypto_GenKey(size_t key_length, void **key_out) CHK_ARG_NONNULL(key_out); CHK_ARG_EXPR(key_length == 16 || key_length == 32); - BSL_CryptoKey_t *new_key = BSL_MALLOC(sizeof(BSL_CryptoKey_t)); + BSL_CryptoKey_t *new_key = BSL_malloc(sizeof(BSL_CryptoKey_t)); CHK_PROPERTY(new_key); BSL_CryptoKey_Init(new_key); diff --git a/src/mock_bpa/agent.c b/src/mock_bpa/agent.c index a3cc5da..4ff3c2c 100644 --- a/src/mock_bpa/agent.c +++ b/src/mock_bpa/agent.c @@ -75,7 +75,7 @@ int MockBPA_GetBundleMetadata(const BSL_BundleRef_t *bundle_ref, BSL_PrimaryBloc result_primary_block->block_count = MockBPA_BlockList_size(bundle->blocks); - result_primary_block->block_numbers = BSL_CALLOC(result_primary_block->block_count, sizeof(uint64_t)); + result_primary_block->block_numbers = BSL_calloc(result_primary_block->block_count, sizeof(uint64_t)); if (!result_primary_block->block_numbers) { return -2; @@ -136,12 +136,12 @@ int MockBPA_ReallocBTSD(BSL_BundleRef_t *bundle_ref, uint64_t block_num, size_t if (found_block->btsd == NULL) { - found_block->btsd = BSL_CALLOC(1, bytesize); + found_block->btsd = BSL_calloc(1, bytesize); found_block->btsd_len = bytesize; } else { - found_block->btsd = BSL_REALLOC(found_block->btsd, bytesize); + found_block->btsd = BSL_realloc(found_block->btsd, bytesize); found_block->btsd_len = bytesize; } @@ -185,7 +185,7 @@ static void MockBPA_ReadBTSD_Deinit(void *user_data) fclose(obj->file); // buffer is external data, no cleanup - BSL_FREE(obj); + BSL_free(obj); } static struct BSL_SeqReader_s *MockBPA_ReadBTSD(const BSL_BundleRef_t *bundle_ref, uint64_t block_num) @@ -198,7 +198,7 @@ static struct BSL_SeqReader_s *MockBPA_ReadBTSD(const BSL_BundleRef_t *bundle_re } MockBPA_CanonicalBlock_t *found_block = *found_ptr; - struct MockBPA_BTSD_Data_s *obj = BSL_CALLOC(1, sizeof(struct MockBPA_BTSD_Data_s)); + struct MockBPA_BTSD_Data_s *obj = BSL_calloc(1, sizeof(struct MockBPA_BTSD_Data_s)); if (!obj) { return NULL; @@ -208,10 +208,10 @@ static struct BSL_SeqReader_s *MockBPA_ReadBTSD(const BSL_BundleRef_t *bundle_re obj->size = found_block->btsd_len; obj->file = fmemopen(obj->ptr, obj->size, "rb"); - BSL_SeqReader_t *reader = BSL_CALLOC(1, sizeof(BSL_SeqReader_t)); + BSL_SeqReader_t *reader = BSL_calloc(1, sizeof(BSL_SeqReader_t)); if (!reader) { - BSL_FREE(obj); + BSL_free(obj); return NULL; } reader->user_data = obj; @@ -247,11 +247,11 @@ static void MockBPA_WriteBTSD_Deinit(void *user_data) BSL_LOG_DEBUG("closed block %p with size %zu", obj->block, obj->size); // now write-back the BTSD - BSL_FREE(obj->block->btsd); + BSL_free(obj->block->btsd); obj->block->btsd = obj->ptr; obj->block->btsd_len = obj->size; - BSL_FREE(obj); + BSL_free(obj); } static struct BSL_SeqWriter_s *MockBPA_WriteBTSD(BSL_BundleRef_t *bundle_ref, uint64_t block_num, size_t total_size) @@ -265,7 +265,7 @@ static struct BSL_SeqWriter_s *MockBPA_WriteBTSD(BSL_BundleRef_t *bundle_ref, ui MockBPA_CanonicalBlock_t *found_block = *found_ptr; BSL_LOG_DEBUG("opened block %p for size %zu", found_block, total_size); - struct MockBPA_BTSD_Data_s *obj = BSL_CALLOC(1, sizeof(struct MockBPA_BTSD_Data_s)); + struct MockBPA_BTSD_Data_s *obj = BSL_calloc(1, sizeof(struct MockBPA_BTSD_Data_s)); if (!obj) { return NULL; @@ -276,11 +276,11 @@ static struct BSL_SeqWriter_s *MockBPA_WriteBTSD(BSL_BundleRef_t *bundle_ref, ui obj->size = 0; obj->file = open_memstream(&obj->ptr, &obj->size); - BSL_SeqWriter_t *writer = BSL_CALLOC(1, sizeof(BSL_SeqWriter_t)); + BSL_SeqWriter_t *writer = BSL_calloc(1, sizeof(BSL_SeqWriter_t)); if (!writer) { - BSL_FREE(obj->ptr); - BSL_FREE(obj); + BSL_free(obj->ptr); + BSL_free(obj); return NULL; } writer->user_data = obj; @@ -356,7 +356,7 @@ int MockBPA_RemoveBlock(BSL_BundleRef_t *bundle_ref, uint64_t block_num) } // Deinit and clear the target block for removal - BSL_FREE(found_block->btsd); + BSL_free(found_block->btsd); MockBPA_BlockByNum_erase(bundle->blocks_num, block_num); MockBPA_BlockList_remove(bundle->blocks, bit); @@ -444,7 +444,7 @@ int MockBPA_Agent_Init(MockBPA_Agent_t *agent) { MockBPA_Agent_BSL_Ctx_t *ctx = ctxs[ix]; - ctx->bsl = BSL_CALLOC(1, BSL_LibCtx_Sizeof()); + ctx->bsl = BSL_calloc(1, BSL_LibCtx_Sizeof()); if (BSL_API_InitLib(ctx->bsl)) { BSL_LOG_ERR("Failed BSL_API_InitLib()"); @@ -468,7 +468,7 @@ int MockBPA_Agent_Init(MockBPA_Agent_t *agent) } // TODO find a better way to deal with this { - agent->appin.policy = BSL_CALLOC(1, sizeof(BSLP_PolicyProvider_t)); + agent->appin.policy = BSL_calloc(1, sizeof(BSLP_PolicyProvider_t)); agent->appin.policy->pp_id = 1; BSL_PolicyDesc_t policy_callbacks = (BSL_PolicyDesc_t) { .deinit_fn = BSLP_Deinit, .query_fn = BSLP_QueryPolicy, @@ -477,7 +477,7 @@ int MockBPA_Agent_Init(MockBPA_Agent_t *agent) ASSERT_PROPERTY(BSL_SUCCESS == BSL_API_RegisterPolicyProvider(agent->appin.bsl, 1, policy_callbacks)); } { - agent->appout.policy = BSL_CALLOC(1, sizeof(BSLP_PolicyProvider_t)); + agent->appout.policy = BSL_calloc(1, sizeof(BSLP_PolicyProvider_t)); agent->appout.policy->pp_id = 1; BSL_PolicyDesc_t policy_callbacks = (BSL_PolicyDesc_t) { .deinit_fn = BSLP_Deinit, .query_fn = BSLP_QueryPolicy, @@ -486,7 +486,7 @@ int MockBPA_Agent_Init(MockBPA_Agent_t *agent) ASSERT_PROPERTY(BSL_SUCCESS == BSL_API_RegisterPolicyProvider(agent->appout.bsl, 1, policy_callbacks)); } { - agent->clin.policy = BSL_CALLOC(1, sizeof(BSLP_PolicyProvider_t)); + agent->clin.policy = BSL_calloc(1, sizeof(BSLP_PolicyProvider_t)); agent->clin.policy->pp_id = 1; BSL_PolicyDesc_t policy_callbacks = (BSL_PolicyDesc_t) { .deinit_fn = BSLP_Deinit, .query_fn = BSLP_QueryPolicy, @@ -495,7 +495,7 @@ int MockBPA_Agent_Init(MockBPA_Agent_t *agent) ASSERT_PROPERTY(BSL_SUCCESS == BSL_API_RegisterPolicyProvider(agent->clin.bsl, 1, policy_callbacks)); } { - agent->clout.policy = BSL_CALLOC(1, sizeof(BSLP_PolicyProvider_t)); + agent->clout.policy = BSL_calloc(1, sizeof(BSLP_PolicyProvider_t)); agent->clout.policy->pp_id = 1; BSL_PolicyDesc_t policy_callbacks = (BSL_PolicyDesc_t) { .deinit_fn = BSLP_Deinit, .query_fn = BSLP_QueryPolicy, @@ -534,7 +534,7 @@ void MockBPA_Agent_Deinit(MockBPA_Agent_t *agent) { BSL_LOG_ERR("Failed BSL_API_DeinitLib()"); } - BSL_FREE(ctx->bsl); + BSL_free(ctx->bsl); ctx->bsl = NULL; } @@ -648,8 +648,8 @@ static int MockBPA_Agent_process(MockBPA_Agent_t *agent, MockBPA_Agent_BSL_Ctx_t return 2; } - BSL_SecurityActionSet_t *malloced_action_set = BSL_CALLOC(1, BSL_SecurityActionSet_Sizeof()); - BSL_SecurityResponseSet_t *malloced_response_set = BSL_CALLOC(1, BSL_SecurityResponseSet_Sizeof()); + BSL_SecurityActionSet_t *malloced_action_set = BSL_calloc(1, BSL_SecurityActionSet_Sizeof()); + BSL_SecurityResponseSet_t *malloced_response_set = BSL_calloc(1, BSL_SecurityResponseSet_Sizeof()); BSL_BundleRef_t bundle_ref = { .data = bundle }; BSL_LOG_INFO("calling BSL_API_QuerySecurity"); @@ -677,8 +677,8 @@ static int MockBPA_Agent_process(MockBPA_Agent_t *agent, MockBPA_Agent_BSL_Ctx_t MockBPA_Agent_DumpTelemetry(agent); BSL_SecurityActionSet_Deinit(malloced_action_set); - BSL_FREE(malloced_action_set); - BSL_FREE(malloced_response_set); + BSL_free(malloced_action_set); + BSL_free(malloced_response_set); BSL_LOG_INFO("result code %d", returncode); return returncode; } diff --git a/src/mock_bpa/bundle.c b/src/mock_bpa/bundle.c index b73ef7a..b9cefc2 100644 --- a/src/mock_bpa/bundle.c +++ b/src/mock_bpa/bundle.c @@ -49,7 +49,7 @@ int MockBPA_Bundle_Deinit(MockBPA_Bundle_t *bundle) { MockBPA_CanonicalBlock_t *blk = MockBPA_BlockList_ref(bit); BSL_LOG_DEBUG("freeing block number %" PRIu64, blk->blk_num); - BSL_FREE(blk->btsd); + BSL_free(blk->btsd); } MockBPA_BlockList_clear(bundle->blocks); diff --git a/src/mock_bpa/ctr.c b/src/mock_bpa/ctr.c index d17a3b3..550dd1c 100644 --- a/src/mock_bpa/ctr.c +++ b/src/mock_bpa/ctr.c @@ -33,7 +33,7 @@ void mock_bpa_ctr_init(mock_bpa_ctr_t *ctr) BSL_Data_Init(&(ctr->encoded)); - ctr->bundle = BSL_CALLOC(1, sizeof(MockBPA_Bundle_t)); + ctr->bundle = BSL_calloc(1, sizeof(MockBPA_Bundle_t)); MockBPA_Bundle_Init(ctr->bundle); ctr->bundle_ref.data = ctr->bundle; @@ -60,7 +60,7 @@ void mock_bpa_ctr_deinit(mock_bpa_ctr_t *ctr) if (ctr->bundle) { MockBPA_Bundle_Deinit(ctr->bundle); - BSL_FREE(ctr->bundle); + BSL_free(ctr->bundle); } } diff --git a/src/mock_bpa/decode.c b/src/mock_bpa/decode.c index ff429f7..254173c 100644 --- a/src/mock_bpa/decode.c +++ b/src/mock_bpa/decode.c @@ -254,14 +254,14 @@ int bsl_mock_decode_canonical(QCBORDecodeContext *dec, MockBPA_CanonicalBlock_t { if (blk->btsd) { - BSL_FREE(blk->btsd); + BSL_free(blk->btsd); blk->btsd = NULL; } blk->btsd_len = view.len; if (blk->btsd_len > 0) { - blk->btsd = BSL_MALLOC(view.len); + blk->btsd = BSL_malloc(view.len); // GCOV_EXCL_START ASSERT_ARG_NONNULL(blk->btsd); // GCOV_EXCL_STOP diff --git a/src/mock_bpa/eid.c b/src/mock_bpa/eid.c index 94052ab..2f75172 100644 --- a/src/mock_bpa/eid.c +++ b/src/mock_bpa/eid.c @@ -57,7 +57,7 @@ int MockBPA_EID_Init(void *user_data _U_, BSL_HostEID_t *eid) { BSL_CHKERR1(eid); memset(eid, 0, sizeof(BSL_HostEID_t)); - eid->handle = BSL_MALLOC(sizeof(bsl_mock_eid_t)); + eid->handle = BSL_malloc(sizeof(bsl_mock_eid_t)); if (!(eid->handle)) { return -2; @@ -72,7 +72,7 @@ void MockBPA_EID_Deinit(void *user_data _U_, BSL_HostEID_t *eid) if (eid->handle) { bsl_mock_eid_deinit(eid->handle); - BSL_FREE(eid->handle); + BSL_free(eid->handle); } memset(eid, 0, sizeof(BSL_HostEID_t)); } diff --git a/src/mock_bpa/eidpat.c b/src/mock_bpa/eidpat.c index 2d54df8..e1b7e06 100644 --- a/src/mock_bpa/eidpat.c +++ b/src/mock_bpa/eidpat.c @@ -389,7 +389,7 @@ int mock_bpa_eidpat_init(BSL_HostEIDPattern_t *pat, void *user_data _U_) BSL_CHKERR1(pat); // GCOV_EXCL_LINE memset(pat, 0, sizeof(BSL_HostEIDPattern_t)); - pat->handle = BSL_MALLOC(sizeof(bsl_mock_eidpat_t)); + pat->handle = BSL_malloc(sizeof(bsl_mock_eidpat_t)); if (!(pat->handle)) { return 2; // GCOV_EXCL_LINE @@ -416,7 +416,7 @@ void mock_bpa_eidpat_deinit(BSL_HostEIDPattern_t *pat, void *user_data _U_) if (pat->handle) { bsl_mock_eidpat_deinit(pat->handle); - BSL_FREE(pat->handle); + BSL_free(pat->handle); } memset(pat, 0, sizeof(BSL_HostEIDPattern_t)); } diff --git a/src/mock_bpa/mock_bpa.c b/src/mock_bpa/mock_bpa.c index b15f225..0a8aa5e 100644 --- a/src/mock_bpa/mock_bpa.c +++ b/src/mock_bpa/mock_bpa.c @@ -104,6 +104,11 @@ static void show_usage(const char *argv0) int main(int argc, char **argv) { + if (BSL_HostDescriptors_Set(MockBPA_Agent_Descriptors(&agent))) + { + return 2; + } + BSL_openlog(); int retval = 0; int res; @@ -121,11 +126,7 @@ int main(int argc, char **argv) sigaction(SIGINT, &stopper, NULL); sigaction(SIGTERM, &stopper, NULL); } - // always run these steps - if (BSL_HostDescriptors_Set(MockBPA_Agent_Descriptors(&agent))) - { - retval = 2; - } + BSL_HostEID_Init(&app_eid); BSL_HostEID_Init(&sec_eid); @@ -252,8 +253,8 @@ int main(int argc, char **argv) BSL_HostEID_Deinit(&sec_eid); BSL_HostEID_Deinit(&app_eid); - BSL_HostDescriptors_Clear(); BSL_CryptoDeinit(); BSL_closelog(); + BSL_HostDescriptors_Clear(); return retval; } diff --git a/src/mock_bpa/policy_params.c b/src/mock_bpa/policy_params.c index f51662b..2ebd69a 100644 --- a/src/mock_bpa/policy_params.c +++ b/src/mock_bpa/policy_params.c @@ -29,13 +29,13 @@ void mock_bpa_policy_params_init(mock_bpa_policy_params_t *params, int policy_num) { - params->param_integ_scope_flag = BSL_CALLOC(1, BSL_SecParam_Sizeof()); - params->param_sha_variant = BSL_CALLOC(1, BSL_SecParam_Sizeof()); - params->param_aad_scope_flag = BSL_CALLOC(1, BSL_SecParam_Sizeof()); - params->param_init_vector = BSL_CALLOC(1, BSL_SecParam_Sizeof()); - params->param_aes_variant = BSL_CALLOC(1, BSL_SecParam_Sizeof()); - params->param_test_key = BSL_CALLOC(1, BSL_SecParam_Sizeof()); - params->param_use_wrapped_key = BSL_CALLOC(1, BSL_SecParam_Sizeof()); + params->param_integ_scope_flag = BSL_calloc(1, BSL_SecParam_Sizeof()); + params->param_sha_variant = BSL_calloc(1, BSL_SecParam_Sizeof()); + params->param_aad_scope_flag = BSL_calloc(1, BSL_SecParam_Sizeof()); + params->param_init_vector = BSL_calloc(1, BSL_SecParam_Sizeof()); + params->param_aes_variant = BSL_calloc(1, BSL_SecParam_Sizeof()); + params->param_test_key = BSL_calloc(1, BSL_SecParam_Sizeof()); + params->param_use_wrapped_key = BSL_calloc(1, BSL_SecParam_Sizeof()); params->active = true; @@ -45,19 +45,19 @@ void mock_bpa_policy_params_init(mock_bpa_policy_params_t *params, int policy_nu void mock_bpa_policy_params_deinit(mock_bpa_policy_params_t *params, int policy_num) { BSL_SecParam_Deinit(params->param_integ_scope_flag); - BSL_FREE(params->param_integ_scope_flag); + BSL_free(params->param_integ_scope_flag); BSL_SecParam_Deinit(params->param_sha_variant); - BSL_FREE(params->param_sha_variant); + BSL_free(params->param_sha_variant); BSL_SecParam_Deinit(params->param_aad_scope_flag); - BSL_FREE(params->param_aad_scope_flag); + BSL_free(params->param_aad_scope_flag); BSL_SecParam_Deinit(params->param_init_vector); - BSL_FREE(params->param_init_vector); + BSL_free(params->param_init_vector); BSL_SecParam_Deinit(params->param_aes_variant); - BSL_FREE(params->param_aes_variant); + BSL_free(params->param_aes_variant); BSL_SecParam_Deinit(params->param_test_key); - BSL_FREE(params->param_test_key); + BSL_free(params->param_test_key); BSL_SecParam_Deinit(params->param_use_wrapped_key); - BSL_FREE(params->param_use_wrapped_key); + BSL_free(params->param_use_wrapped_key); params->active = false; diff --git a/src/policy_provider/SamplePolicyProvider.c b/src/policy_provider/SamplePolicyProvider.c index 0e63548..8d6658c 100644 --- a/src/policy_provider/SamplePolicyProvider.c +++ b/src/policy_provider/SamplePolicyProvider.c @@ -164,7 +164,7 @@ int BSLP_QueryPolicy(const void *user_data, BSL_SecurityActionSet_t *output_acti return BSL_ERR_HOST_CALLBACK_FAILED; } - BSL_SecurityAction_t *action = BSL_CALLOC(1, BSL_SecurityAction_Sizeof()); + BSL_SecurityAction_t *action = BSL_calloc(1, BSL_SecurityAction_Sizeof()); BSL_SecurityAction_Init(action); BSLP_SecOperPtrList_t secops; @@ -195,14 +195,14 @@ int BSLP_QueryPolicy(const void *user_data, BSL_SecurityActionSet_t *output_acti continue; } - BSL_SecOper_t *sec_oper = BSL_CALLOC(1, BSL_SecOper_Sizeof()); + BSL_SecOper_t *sec_oper = BSL_calloc(1, BSL_SecOper_Sizeof()); BSL_SecOper_Init(sec_oper); if (BSLP_PolicyRule_EvaluateAsSecOper(rule, sec_oper, bundle, location) < 0) { BSL_LOG_WARNING("SecOp evaluate failed"); BSL_SecurityAction_IncrError(action); BSL_SecOper_Deinit(sec_oper); - BSL_FREE(sec_oper); + BSL_free(sec_oper); continue; } @@ -279,13 +279,13 @@ int BSLP_QueryPolicy(const void *user_data, BSL_SecurityActionSet_t *output_acti { BSL_SecOper_t **secop = BSLP_SecOperPtrList_get(secops, i); BSL_SecurityAction_AppendSecOper(action, *secop); - BSL_FREE(*secop); + BSL_free(*secop); } BSLP_SecOperPtrList_clear(secops); BSL_SecurityActionSet_AppendAction(output_action_set, action); BSL_SecurityAction_Deinit(action); - BSL_FREE(action); + BSL_free(action); CHK_POSTCONDITION(BSL_SecurityActionSet_IsConsistent(output_action_set)); return (int)BSL_SecurityActionSet_CountErrors(output_action_set); @@ -370,7 +370,7 @@ void BSLP_Deinit(void *user_data) BSLP_PolicyPredicate_Deinit(&self->predicates[index]); } memset(self, 0, sizeof(*self)); - BSL_FREE(user_data); + BSL_free(user_data); } void BSLP_PolicyPredicate_Init(BSLP_PolicyPredicate_t *self, BSL_PolicyLocation_e location, @@ -422,7 +422,7 @@ int BSLP_PolicyRule_Init(BSLP_PolicyRule_t *self, const char *desc, BSLP_PolicyP memset(self, 0, sizeof(*self)); size_t desc_sz = strnlen(desc, BSLP_POLICYPREDICATE_ARRAY_CAPACITY); - self->description = BSL_MALLOC(desc_sz + 1); + self->description = BSL_malloc(desc_sz + 1); strncpy(self->description, desc, desc_sz); self->description[desc_sz] = '\0'; @@ -442,7 +442,7 @@ void BSLP_PolicyRule_Deinit(BSLP_PolicyRule_t *self) { ASSERT_ARG_EXPR(BSLP_PolicyRule_IsConsistent(self)); BSL_LOG_INFO("BSLP_PolicyRule_Deinit: %s, nparams=%zu", self->description, BSLB_SecParamList_size(self->params)); - BSL_FREE(self->description); + BSL_free(self->description); BSLB_SecParamList_clear(self->params); memset(self, 0, sizeof(*self)); } diff --git a/src/security_context/BCB_AES_GCM.c b/src/security_context/BCB_AES_GCM.c index 6eae1e2..e232467 100644 --- a/src/security_context/BCB_AES_GCM.c +++ b/src/security_context/BCB_AES_GCM.c @@ -651,14 +651,14 @@ int BSLX_BCB_Execute(BSL_LibCtx_t *lib _U_, BSL_BundleRef_t *bundle, const BSL_S // If present, append it to the result. if (bcb_context.authtag.len > 0) { - BSL_SecResult_t *auth_tag = BSL_CALLOC(1, BSL_SecResult_Sizeof()); + BSL_SecResult_t *auth_tag = BSL_calloc(1, BSL_SecResult_Sizeof()); if (BSL_SUCCESS != BSL_SecResult_InitFull(auth_tag, RFC9173_BCB_RESULTID_AUTHTAG, RFC9173_CONTEXTID_BCB_AES_GCM, BSL_SecOper_GetTargetBlockNum(sec_oper), &bcb_context.authtag)) { BSL_LOG_ERR("Failed to append BCB auth tag"); BSL_SecResult_Deinit(auth_tag); - BSL_FREE(auth_tag); + BSL_free(auth_tag); BSLX_BCB_Deinit(&bcb_context); return BSL_ERR_SECURITY_CONTEXT_FAILED; } @@ -668,17 +668,17 @@ int BSLX_BCB_Execute(BSL_LibCtx_t *lib _U_, BSL_BundleRef_t *bundle, const BSL_S BSL_SecOutcome_AppendResult(sec_outcome, auth_tag); } BSL_SecResult_Deinit(auth_tag); - BSL_FREE(auth_tag); + BSL_free(auth_tag); } if (bcb_context.iv.len > 0) { - BSL_SecParam_t *iv_param = BSL_CALLOC(1, BSL_SecParam_Sizeof()); + BSL_SecParam_t *iv_param = BSL_calloc(1, BSL_SecParam_Sizeof()); if (BSL_SUCCESS != BSL_SecParam_InitBytestr(iv_param, RFC9173_BCB_SECPARAM_IV, bcb_context.iv)) { BSL_LOG_ERR("Failed to append BCB source IV"); BSL_SecParam_Deinit(iv_param); - BSL_FREE(iv_param); + BSL_free(iv_param); BSLX_BCB_Deinit(&bcb_context); return BSL_ERR_SECURITY_CONTEXT_FAILED; } @@ -688,15 +688,15 @@ int BSLX_BCB_Execute(BSL_LibCtx_t *lib _U_, BSL_BundleRef_t *bundle, const BSL_S BSL_SecOutcome_AppendParam(sec_outcome, iv_param); } BSL_SecParam_Deinit(iv_param); - BSL_FREE(iv_param); + BSL_free(iv_param); } - BSL_SecParam_t *aes_param = BSL_CALLOC(1, BSL_SecParam_Sizeof()); + BSL_SecParam_t *aes_param = BSL_calloc(1, BSL_SecParam_Sizeof()); if (BSL_SUCCESS != BSL_SecParam_InitInt64(aes_param, RFC9173_BCB_SECPARAM_AESVARIANT, bcb_context.aes_variant)) { BSL_LOG_ERR("Failed to append BCB AES param"); BSL_SecParam_Deinit(aes_param); - BSL_FREE(aes_param); + BSL_free(aes_param); BSLX_BCB_Deinit(&bcb_context); return BSL_ERR_SECURITY_CONTEXT_FAILED; } @@ -706,18 +706,18 @@ int BSLX_BCB_Execute(BSL_LibCtx_t *lib _U_, BSL_BundleRef_t *bundle, const BSL_S BSL_SecOutcome_AppendParam(sec_outcome, aes_param); } BSL_SecParam_Deinit(aes_param); - BSL_FREE(aes_param); + BSL_free(aes_param); if (bcb_context.wrapped_key.len > 0) { - BSL_SecParam_t *aes_wrapped_key_param = BSL_CALLOC(1, BSL_SecParam_Sizeof()); + BSL_SecParam_t *aes_wrapped_key_param = BSL_calloc(1, BSL_SecParam_Sizeof()); if (BSL_SUCCESS != BSL_SecParam_InitBytestr(aes_wrapped_key_param, RFC9173_BCB_SECPARAM_WRAPPEDKEY, bcb_context.wrapped_key)) { BSL_LOG_ERR("Failed to append BCB wrapped key param"); BSL_SecParam_Deinit(aes_wrapped_key_param); - BSL_FREE(aes_wrapped_key_param); + BSL_free(aes_wrapped_key_param); BSLX_BCB_Deinit(&bcb_context); return BSL_ERR_SECURITY_CONTEXT_FAILED; } @@ -727,15 +727,15 @@ int BSLX_BCB_Execute(BSL_LibCtx_t *lib _U_, BSL_BundleRef_t *bundle, const BSL_S BSL_SecOutcome_AppendParam(sec_outcome, aes_wrapped_key_param); } BSL_SecParam_Deinit(aes_wrapped_key_param); - BSL_FREE(aes_wrapped_key_param); + BSL_free(aes_wrapped_key_param); } - BSL_SecParam_t *scope_flag_param = BSL_CALLOC(1, BSL_SecParam_Sizeof()); + BSL_SecParam_t *scope_flag_param = BSL_calloc(1, BSL_SecParam_Sizeof()); if (BSL_SUCCESS != BSL_SecParam_InitInt64(scope_flag_param, RFC9173_BCB_SECPARAM_AADSCOPE, bcb_context.aad_scope)) { BSL_LOG_ERR("Failed to append BCB scope flag param"); BSL_SecParam_Deinit(scope_flag_param); - BSL_FREE(scope_flag_param); + BSL_free(scope_flag_param); BSLX_BCB_Deinit(&bcb_context); return BSL_ERR_SECURITY_CONTEXT_FAILED; } @@ -745,7 +745,7 @@ int BSLX_BCB_Execute(BSL_LibCtx_t *lib _U_, BSL_BundleRef_t *bundle, const BSL_S BSL_SecOutcome_AppendParam(sec_outcome, scope_flag_param); } BSL_SecParam_Deinit(scope_flag_param); - BSL_FREE(scope_flag_param); + BSL_free(scope_flag_param); BSLX_BCB_Deinit(&bcb_context); return BSL_SUCCESS; diff --git a/src/security_context/BIB_HMAC_SHA2.c b/src/security_context/BIB_HMAC_SHA2.c index e60acf3..cb95164 100644 --- a/src/security_context/BIB_HMAC_SHA2.c +++ b/src/security_context/BIB_HMAC_SHA2.c @@ -515,23 +515,23 @@ int BSLX_BIB_Execute(BSL_LibCtx_t *lib, BSL_BundleRef_t *bundle, const BSL_SecOp } { - BSL_SecResult_t *bib_result = BSL_CALLOC(1, BSL_SecResult_Sizeof()); + BSL_SecResult_t *bib_result = BSL_calloc(1, BSL_SecResult_Sizeof()); BSL_SecResult_InitFull(bib_result, RFC9173_BIB_RESULTID_HMAC, RFC9173_CONTEXTID_BIB_HMAC_SHA2, BSL_SecOper_GetTargetBlockNum(sec_oper), &bib_context.hmac_result_val); BSL_SecOutcome_AppendResult(sec_outcome, bib_result); BSL_SecResult_Deinit(bib_result); - BSL_FREE(bib_result); + BSL_free(bib_result); } if (bib_context.wrapped_key.len > 0) { - BSL_SecParam_t *wrapped_key_param = BSL_CALLOC(1, BSL_SecParam_Sizeof()); + BSL_SecParam_t *wrapped_key_param = BSL_calloc(1, BSL_SecParam_Sizeof()); if (BSL_SUCCESS != BSL_SecParam_InitBytestr(wrapped_key_param, RFC9173_BIB_PARAMID_WRAPPED_KEY, bib_context.wrapped_key)) { BSL_LOG_ERR("Failed to append BIB wrapped key param"); BSL_SecParam_Deinit(wrapped_key_param); - BSL_FREE(wrapped_key_param); + BSL_free(wrapped_key_param); BSLX_BIB_Deinit(&bib_context); return BSL_ERR_SECURITY_CONTEXT_FAILED; } @@ -541,7 +541,7 @@ int BSLX_BIB_Execute(BSL_LibCtx_t *lib, BSL_BundleRef_t *bundle, const BSL_SecOp BSL_SecOutcome_AppendParam(sec_outcome, wrapped_key_param); } BSL_SecParam_Deinit(wrapped_key_param); - BSL_FREE(wrapped_key_param); + BSL_free(wrapped_key_param); } BSLX_BIB_Deinit(&bib_context); diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index c20fa3c..6de4a06 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -89,6 +89,10 @@ if(BUILD_UNITTEST AND NOT BUILD_FUZZING) # Exercises the MockBPA using the publicly exposed BSL front end add_unity_test(SOURCE test_PublicInterfaceImpl.c) target_link_libraries(test_PublicInterfaceImpl PUBLIC ${LIB_ORDERED}) + + # Test user-specified dynamic mem mgmt callbacks + add_unity_test(SOURCE test_DynamicMemCbs.c) + target_link_libraries(test_DynamicMemCbs PUBLIC ${LIB_ORDERED}) endif(BUILD_UNITTEST AND NOT BUILD_FUZZING) if(BUILD_FUZZING) diff --git a/test/bsl_test_utils.c b/test/bsl_test_utils.c index f246e27..a6c5b21 100644 --- a/test/bsl_test_utils.c +++ b/test/bsl_test_utils.c @@ -144,22 +144,22 @@ void BSL_TestUtils_InitBCB_Appendix2(BCBTestContext *context, BSL_SecRole_e role BSL_SecurityActionSet_t *BSL_TestUtils_InitMallocBIBActionSet(BIBTestContext *bib_context) { - BSL_SecurityActionSet_t *action_set = BSL_CALLOC(1, sizeof(BSL_SecurityActionSet_t)); + BSL_SecurityActionSet_t *action_set = BSL_calloc(1, sizeof(BSL_SecurityActionSet_t)); BSL_SecurityActionSet_Init(action_set); - BSL_SecurityAction_t *act = BSL_CALLOC(1, sizeof(BSL_SecurityAction_t)); + BSL_SecurityAction_t *act = BSL_calloc(1, sizeof(BSL_SecurityAction_t)); BSL_SecurityAction_Init(act); BSL_SecurityAction_AppendSecOper(act, &bib_context->sec_oper); // ensure consistent context state BSL_SecOper_Init(&bib_context->sec_oper); BSL_SecurityActionSet_AppendAction(action_set, act); BSL_SecurityAction_Deinit(act); - BSL_FREE(act); + BSL_free(act); return action_set; } BSL_SecurityResponseSet_t *BSL_TestUtils_MallocEmptyPolicyResponse(void) { - return BSL_CALLOC(1, BSL_SecurityResponseSet_Sizeof()); + return BSL_calloc(1, BSL_SecurityResponseSet_Sizeof()); } int rfc9173_byte_gen_fn_a1(unsigned char *buf, int len) @@ -490,12 +490,12 @@ static void BSL_TestUtils_ReadBTSD_Deinit(void *user_data) fclose(obj->file); // buffer is external data, no cleanup - BSL_FREE(obj); + BSL_free(obj); } BSL_SeqReader_t *BSL_TestUtils_FlatReader(const void *buf, size_t bufsize) { - struct BSL_TestUtils_Flat_Data_s *obj = BSL_CALLOC(1, sizeof(struct BSL_TestUtils_Flat_Data_s)); + struct BSL_TestUtils_Flat_Data_s *obj = BSL_calloc(1, sizeof(struct BSL_TestUtils_Flat_Data_s)); ASSERT_PROPERTY(obj); obj->origbuf = NULL; obj->origsize = NULL; @@ -503,7 +503,7 @@ BSL_SeqReader_t *BSL_TestUtils_FlatReader(const void *buf, size_t bufsize) obj->size = bufsize; obj->file = fmemopen(obj->ptr, obj->size, "rb"); - BSL_SeqReader_t *reader = BSL_MALLOC(sizeof(BSL_SeqReader_t)); + BSL_SeqReader_t *reader = BSL_malloc(sizeof(BSL_SeqReader_t)); ASSERT_PROPERTY(reader); reader->user_data = obj; reader->read = BSL_TestUtils_ReadBTSD_Read; @@ -548,12 +548,12 @@ static void BSL_TestUtils_WriteBTSD_Deinit(void *user_data) *obj->origsize = obj->size; } - BSL_FREE(obj); + BSL_free(obj); } BSL_SeqWriter_t *BSL_TestUtils_FlatWriter(void **buf, size_t *bufsize) { - struct BSL_TestUtils_Flat_Data_s *obj = BSL_CALLOC(1, sizeof(struct BSL_TestUtils_Flat_Data_s)); + struct BSL_TestUtils_Flat_Data_s *obj = BSL_calloc(1, sizeof(struct BSL_TestUtils_Flat_Data_s)); ASSERT_PROPERTY(obj); // double-buffer for this write obj->origbuf = buf; @@ -562,7 +562,7 @@ BSL_SeqWriter_t *BSL_TestUtils_FlatWriter(void **buf, size_t *bufsize) obj->size = 0; obj->file = open_memstream(&obj->ptr, &obj->size); - BSL_SeqWriter_t *writer = BSL_MALLOC(sizeof(BSL_SeqWriter_t)); + BSL_SeqWriter_t *writer = BSL_malloc(sizeof(BSL_SeqWriter_t)); ASSERT_PROPERTY(writer); writer->user_data = obj; writer->write = BSL_TestUtils_WriteBTSD_Write; diff --git a/test/fuzz_dynamic_asb_cbor.cpp b/test/fuzz_dynamic_asb_cbor.cpp index fa9f37d..9a42379 100644 --- a/test/fuzz_dynamic_asb_cbor.cpp +++ b/test/fuzz_dynamic_asb_cbor.cpp @@ -34,9 +34,9 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size); extern "C" int LLVMFuzzerInitialize(int *argc _U_, char ***argv _U_) { + BSL_HostDescriptors_Set(MockBPA_Agent_Descriptors(NULL)); BSL_openlog(); BSL_LogSetLeastSeverity(LOG_CRIT); - BSL_HostDescriptors_Set(MockBPA_Agent_Descriptors(NULL)); return 0; } @@ -44,7 +44,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { int retval = 0; - BSL_AbsSecBlock_t *asb = (BSL_AbsSecBlock_t *)BSL_MALLOC(BSL_AbsSecBlock_Sizeof()); + BSL_AbsSecBlock_t *asb = (BSL_AbsSecBlock_t *)BSL_malloc(BSL_AbsSecBlock_Sizeof()); BSL_AbsSecBlock_InitEmpty(asb); { @@ -90,7 +90,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) BSL_Data_Deinit(&out_data); BSL_AbsSecBlock_Deinit(asb); - BSL_FREE(asb); + BSL_free(asb); return retval; } diff --git a/test/fuzz_mock_bpa_bpv7_cbor.cpp b/test/fuzz_mock_bpa_bpv7_cbor.cpp index 5c98bfa..0074f44 100644 --- a/test/fuzz_mock_bpa_bpv7_cbor.cpp +++ b/test/fuzz_mock_bpa_bpv7_cbor.cpp @@ -34,9 +34,9 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size); extern "C" int LLVMFuzzerInitialize(int *argc _U_, char ***argv _U_) { + BSL_HostDescriptors_Set(MockBPA_Agent_Descriptors(NULL)); BSL_openlog(); BSL_LogSetLeastSeverity(LOG_CRIT); - BSL_HostDescriptors_Set(MockBPA_Agent_Descriptors(NULL)); return 0; } diff --git a/test/fuzz_mock_bpa_eid_cbor.cpp b/test/fuzz_mock_bpa_eid_cbor.cpp index 4687dd0..d3ec526 100644 --- a/test/fuzz_mock_bpa_eid_cbor.cpp +++ b/test/fuzz_mock_bpa_eid_cbor.cpp @@ -34,9 +34,9 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size); extern "C" int LLVMFuzzerInitialize(int *argc _U_, char ***argv _U_) { + BSL_HostDescriptors_Set(MockBPA_Agent_Descriptors(NULL)); BSL_openlog(); BSL_LogSetLeastSeverity(LOG_CRIT); - BSL_HostDescriptors_Set(MockBPA_Agent_Descriptors(NULL)); return 0; } diff --git a/test/fuzz_mock_bpa_eid_uri.cpp b/test/fuzz_mock_bpa_eid_uri.cpp index 9319bf2..2a2a9d0 100644 --- a/test/fuzz_mock_bpa_eid_uri.cpp +++ b/test/fuzz_mock_bpa_eid_uri.cpp @@ -36,9 +36,9 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size); extern "C" int LLVMFuzzerInitialize(int *argc _U_, char ***argv _U_) { + BSL_HostDescriptors_Set(MockBPA_Agent_Descriptors(NULL)); BSL_openlog(); BSL_LogSetLeastSeverity(LOG_CRIT); - BSL_HostDescriptors_Set(MockBPA_Agent_Descriptors(NULL)); return 0; } diff --git a/test/fuzz_mock_bpa_eidpat_text.cpp b/test/fuzz_mock_bpa_eidpat_text.cpp index ad81007..5668807 100644 --- a/test/fuzz_mock_bpa_eidpat_text.cpp +++ b/test/fuzz_mock_bpa_eidpat_text.cpp @@ -36,9 +36,9 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size); extern "C" int LLVMFuzzerInitialize(int *argc _U_, char ***argv _U_) { + BSL_HostDescriptors_Set(MockBPA_Agent_Descriptors(NULL)); BSL_openlog(); BSL_LogSetLeastSeverity(LOG_CRIT); - BSL_HostDescriptors_Set(MockBPA_Agent_Descriptors(NULL)); return 0; } diff --git a/test/test_AbsSecBlock.c b/test/test_AbsSecBlock.c index fbfed4d..72e9506 100644 --- a/test/test_AbsSecBlock.c +++ b/test/test_AbsSecBlock.c @@ -36,14 +36,14 @@ void suiteSetUp(void) { - BSL_openlog(); TEST_ASSERT_EQUAL_INT(0, BSL_HostDescriptors_Set(MockBPA_Agent_Descriptors(NULL))); + BSL_openlog(); } int suiteTearDown(int failures) { - BSL_HostDescriptors_Clear(); BSL_closelog(); + BSL_HostDescriptors_Clear(); return failures; } @@ -52,7 +52,7 @@ void TestASBDecodeEncodeClosure(uint8_t *asb_cbor, size_t asb_cbor_bytelen, int6 { BSL_Data_t asb_cbor_data; BSL_Data_InitView(&asb_cbor_data, asb_cbor_bytelen, asb_cbor); - BSL_AbsSecBlock_t *asb = BSL_CALLOC(1, BSL_AbsSecBlock_Sizeof()); + BSL_AbsSecBlock_t *asb = BSL_calloc(1, BSL_AbsSecBlock_Sizeof()); BSL_AbsSecBlock_InitEmpty(asb); const int decode_result = BSL_AbsSecBlock_DecodeFromCBOR(asb, &asb_cbor_data); @@ -82,7 +82,7 @@ void TestASBDecodeEncodeClosure(uint8_t *asb_cbor, size_t asb_cbor_bytelen, int6 BSL_Data_Deinit(&encoded_cbor); BSL_AbsSecBlock_Deinit(asb); - BSL_FREE(asb); + BSL_free(asb); } // See: https://www.rfc-editor.org/rfc/rfc9173.html#name-abstract-security-block-2 @@ -146,14 +146,14 @@ void test_AbsSecBlock_Decode_failure(const char *hexdata) string_clear(in_text); } - BSL_AbsSecBlock_t *asb = BSL_CALLOC(1, BSL_AbsSecBlock_Sizeof()); + BSL_AbsSecBlock_t *asb = BSL_calloc(1, BSL_AbsSecBlock_Sizeof()); BSL_AbsSecBlock_InitEmpty(asb); const int decode_result = BSL_AbsSecBlock_DecodeFromCBOR(asb, &in_data); TEST_ASSERT_EQUAL_INT(BSL_ERR_DECODING, decode_result); BSL_AbsSecBlock_Deinit(asb); - BSL_FREE(asb); + BSL_free(asb); BSL_Data_Deinit(&in_data); } diff --git a/test/test_BackendPolicyProvider.c b/test/test_BackendPolicyProvider.c index 737c0f7..f01d478 100644 --- a/test/test_BackendPolicyProvider.c +++ b/test/test_BackendPolicyProvider.c @@ -44,14 +44,14 @@ static BSL_TestContext_t LocalTestCtx; void suiteSetUp(void) { - BSL_openlog(); TEST_ASSERT_EQUAL_INT(0, BSL_HostDescriptors_Set(MockBPA_Agent_Descriptors(NULL))); + BSL_openlog(); } int suiteTearDown(int failures) { - BSL_HostDescriptors_Clear(); BSL_closelog(); + BSL_HostDescriptors_Clear(); return failures; } @@ -62,7 +62,7 @@ void setUp(void) TEST_ASSERT_EQUAL(0, BSL_API_InitLib(&LocalTestCtx.bsl)); BSL_PolicyDesc_t policy_desc = { 0 }; - policy_desc.user_data = BSL_CALLOC(1, sizeof(BSLP_PolicyProvider_t)); + policy_desc.user_data = BSL_calloc(1, sizeof(BSLP_PolicyProvider_t)); policy_desc.query_fn = BSLP_QueryPolicy; policy_desc.finalize_fn = BSLP_FinalizePolicy; policy_desc.deinit_fn = BSLP_Deinit; @@ -172,7 +172,7 @@ void test_PolicyProvider_Inspect_RFC9173_BIB(void) void test_MultiplePolicyProviders(void) { BSL_PolicyDesc_t policy_desc_2 = { 0 }; - policy_desc_2.user_data = BSL_CALLOC(1, sizeof(BSLP_PolicyProvider_t)); + policy_desc_2.user_data = BSL_calloc(1, sizeof(BSLP_PolicyProvider_t)); policy_desc_2.query_fn = BSLP_QueryPolicy; policy_desc_2.finalize_fn = BSLP_FinalizePolicy; policy_desc_2.deinit_fn = BSLP_Deinit; @@ -244,5 +244,5 @@ void test_MultiplePolicyProviders(void) &LocalTestCtx.mock_bpa_ctr.bundle_ref, response_set)); BSL_SecurityActionSet_Deinit(&action_set); - BSL_FREE(response_set); + BSL_free(response_set); } diff --git a/test/test_BackendSecurityContext.c b/test/test_BackendSecurityContext.c index 5f36992..40cbbd3 100644 --- a/test/test_BackendSecurityContext.c +++ b/test/test_BackendSecurityContext.c @@ -46,14 +46,14 @@ static BSL_TestContext_t LocalTestCtx; void suiteSetUp(void) { - BSL_openlog(); TEST_ASSERT_EQUAL_INT(0, BSL_HostDescriptors_Set(MockBPA_Agent_Descriptors(NULL))); + BSL_openlog(); } int suiteTearDown(int failures) { - BSL_HostDescriptors_Clear(); BSL_closelog(); + BSL_HostDescriptors_Clear(); return failures; } @@ -117,9 +117,9 @@ void test_SecurityContext_BIB_Source(void) (BSL_TestUtils_IsB16StrEqualTo(RFC9173_TestVectors_AppendixA1.cbor_bundle_bib, mock_bpa_ctr->encoded)); BSL_SecurityResponseSet_Deinit(malloced_responseset); - BSL_FREE(malloced_responseset); + BSL_free(malloced_responseset); BSL_SecurityActionSet_Deinit(malloced_actionset); - BSL_FREE(malloced_actionset); + BSL_free(malloced_actionset); BIBTestContext_Deinit(&bib_test_context); TEST_ASSERT_TRUE(is_expected); @@ -158,9 +158,9 @@ void test_SecurityContext_BIB_Verifier(void) (BSL_TestUtils_IsB16StrEqualTo(RFC9173_TestVectors_AppendixA1.cbor_bundle_bib, mock_bpa_ctr->encoded)); BSL_SecurityActionSet_Deinit(malloced_actionset); - BSL_FREE(malloced_actionset); + BSL_free(malloced_actionset); BSL_SecurityResponseSet_Deinit(malloced_responseset); - BSL_FREE(malloced_responseset); + BSL_free(malloced_responseset); BIBTestContext_Deinit(&bib_test_context); TEST_ASSERT_TRUE(is_match); @@ -207,9 +207,9 @@ void test_SecurityContext_BIB_Verifier_Failure(void) BSL_SECOP_CONCLUSION_FAILURE); BSL_SecurityActionSet_Deinit(malloced_actionset); - BSL_FREE(malloced_actionset); + BSL_free(malloced_actionset); BSL_SecurityResponseSet_Deinit(malloced_responseset); - BSL_FREE(malloced_responseset); + BSL_free(malloced_responseset); BIBTestContext_Deinit(&bib_test_context); } @@ -258,9 +258,9 @@ void test_SecurityContext_BIB_Acceptor(void) cleanup: BSL_SecurityActionSet_Deinit(malloced_actionset); - BSL_FREE(malloced_actionset); + BSL_free(malloced_actionset); BSL_SecurityResponseSet_Deinit(malloced_responseset); - BSL_FREE(malloced_responseset); + BSL_free(malloced_responseset); BIBTestContext_Deinit(&bib_test_context); TEST_ASSERT_EQUAL(0, sec_context_result); @@ -316,10 +316,10 @@ void test_RFC9173_AppendixA_Example3_Acceptor(void) BSL_SecOper_AppendParam(&bcb_oper, &bcb_context.param_test_key_id); BSL_SecOper_AppendParam(&bcb_oper, &bcb_context.use_key_wrap); - BSL_SecurityActionSet_t *malloced_actionset = BSL_CALLOC(1, BSL_SecurityActionSet_Sizeof()); + BSL_SecurityActionSet_t *malloced_actionset = BSL_calloc(1, BSL_SecurityActionSet_Sizeof()); BSL_SecurityActionSet_Init(malloced_actionset); - BSL_SecurityAction_t *malloced_action = BSL_CALLOC(1, BSL_SecurityAction_Sizeof()); + BSL_SecurityAction_t *malloced_action = BSL_calloc(1, BSL_SecurityAction_Sizeof()); BSL_SecurityAction_Init(malloced_action); BSL_SecurityAction_AppendSecOper(malloced_action, &bib_oper_ext_block); BSL_SecurityAction_AppendSecOper(malloced_action, &bcb_oper); @@ -334,11 +334,11 @@ void test_RFC9173_AppendixA_Example3_Acceptor(void) TEST_ASSERT_EQUAL(BSL_SUCCESS, exec_result); BSL_SecurityAction_Deinit(malloced_action); - BSL_FREE(malloced_action); + BSL_free(malloced_action); BSL_SecurityActionSet_Deinit(malloced_actionset); - BSL_FREE(malloced_actionset); + BSL_free(malloced_actionset); BSL_SecurityResponseSet_Deinit(malloced_responseset); - BSL_FREE(malloced_responseset); + BSL_free(malloced_responseset); BSL_PrimaryBlock_deinit(&primary_block); BIBTestContext_Deinit(&bib_context); BCBTestContext_Deinit(&bcb_context); @@ -400,10 +400,10 @@ void test_RFC9173_AppendixA_Example3_Source(void) BSL_SecOper_AppendParam(&bcb_oper, &bcb_context.param_aes_variant); BSL_SecOper_AppendParam(&bcb_oper, &bcb_context.use_key_wrap); - BSL_SecurityActionSet_t *malloced_actionset = BSL_CALLOC(1, BSL_SecurityActionSet_Sizeof()); + BSL_SecurityActionSet_t *malloced_actionset = BSL_calloc(1, BSL_SecurityActionSet_Sizeof()); BSL_SecurityActionSet_Init(malloced_actionset); - BSL_SecurityAction_t *malloced_action = BSL_CALLOC(1, BSL_SecurityAction_Sizeof()); + BSL_SecurityAction_t *malloced_action = BSL_calloc(1, BSL_SecurityAction_Sizeof()); BSL_SecurityAction_Init(malloced_action); BSL_SecurityAction_AppendSecOper(malloced_action, &bib_oper_primary); BSL_SecurityAction_AppendSecOper(malloced_action, &bib_oper_ext_block); @@ -430,11 +430,11 @@ void test_RFC9173_AppendixA_Example3_Source(void) BSL_SecurityResponseSet_Deinit(malloced_responseset); BSL_SecurityAction_Deinit(malloced_action); - BSL_FREE(malloced_action); + BSL_free(malloced_action); BSL_SecurityActionSet_Deinit(malloced_actionset); - BSL_FREE(malloced_actionset); + BSL_free(malloced_actionset); BSL_SecurityResponseSet_Deinit(malloced_responseset); - BSL_FREE(malloced_responseset); + BSL_free(malloced_responseset); BSL_PrimaryBlock_deinit(&primary_block); BIBTestContext_Deinit(&bib_context); BCBTestContext_Deinit(&bcb_context); @@ -510,10 +510,10 @@ void test_RFC9173_AppendixA_Example4_Acceptor(void) BSL_SecOper_AppendParam(&bib_oper_payload, &bib_context.param_scope_flags); BSL_SecOper_AppendParam(&bib_oper_payload, &bib_context.use_key_wrap); - BSL_SecurityActionSet_t *malloced_actionset = BSL_CALLOC(1, BSL_SecurityActionSet_Sizeof()); + BSL_SecurityActionSet_t *malloced_actionset = BSL_calloc(1, BSL_SecurityActionSet_Sizeof()); BSL_SecurityActionSet_Init(malloced_actionset); - BSL_SecurityAction_t *malloced_action = BSL_CALLOC(1, BSL_SecurityAction_Sizeof()); + BSL_SecurityAction_t *malloced_action = BSL_calloc(1, BSL_SecurityAction_Sizeof()); BSL_SecurityAction_Init(malloced_action); BSL_SecurityAction_AppendSecOper(malloced_action, &bcb_op_tgt_payload); BSL_SecurityAction_AppendSecOper(malloced_action, &bcb_op_tgt_bib); @@ -536,11 +536,11 @@ void test_RFC9173_AppendixA_Example4_Acceptor(void) TEST_ASSERT_TRUE(BSL_TestUtils_IsB16StrEqualTo(expected_processed_bundle, mock_bpa_ctr->encoded)); BSL_SecurityAction_Deinit(malloced_action); - BSL_FREE(malloced_action); + BSL_free(malloced_action); BSL_SecurityActionSet_Deinit(malloced_actionset); - BSL_FREE(malloced_actionset); + BSL_free(malloced_actionset); BSL_SecurityResponseSet_Deinit(malloced_responseset); - BSL_FREE(malloced_responseset); + BSL_free(malloced_responseset); BSL_PrimaryBlock_deinit(&primary_block); BIBTestContext_Deinit(&bib_context); BCBTestContext_Deinit(&bcb_context); @@ -603,10 +603,10 @@ void test_RFC9173_AppendixA_Example4_Source(void) BSL_SecOper_AppendParam(&bcb_op_tgt_bib, &bcb_context.param_aes_variant); BSL_SecOper_AppendParam(&bcb_op_tgt_bib, &bcb_context.use_key_wrap); - BSL_SecurityActionSet_t *malloced_actionset = BSL_CALLOC(1, BSL_SecurityActionSet_Sizeof()); + BSL_SecurityActionSet_t *malloced_actionset = BSL_calloc(1, BSL_SecurityActionSet_Sizeof()); BSL_SecurityActionSet_Init(malloced_actionset); - BSL_SecurityAction_t *malloced_action = BSL_CALLOC(1, BSL_SecurityAction_Sizeof()); + BSL_SecurityAction_t *malloced_action = BSL_calloc(1, BSL_SecurityAction_Sizeof()); BSL_SecurityAction_Init(malloced_action); BSL_SecurityAction_AppendSecOper(malloced_action, &bib_oper_payload); BSL_SecurityAction_AppendSecOper(malloced_action, &bcb_op_tgt_payload); @@ -626,11 +626,11 @@ void test_RFC9173_AppendixA_Example4_Source(void) TEST_ASSERT_TRUE(primary_block.block_count <= 4); BSL_SecurityAction_Deinit(malloced_action); - BSL_FREE(malloced_action); + BSL_free(malloced_action); BSL_SecurityActionSet_Deinit(malloced_actionset); - BSL_FREE(malloced_actionset); + BSL_free(malloced_actionset); BSL_SecurityResponseSet_Deinit(malloced_responseset); - BSL_FREE(malloced_responseset); + BSL_free(malloced_responseset); BSL_PrimaryBlock_deinit(&primary_block); BIBTestContext_Deinit(&bib_context); BCBTestContext_Deinit(&bcb_context); diff --git a/test/test_CryptoInterface.c b/test/test_CryptoInterface.c index 184d6e7..bbc7048 100644 --- a/test/test_CryptoInterface.c +++ b/test/test_CryptoInterface.c @@ -30,6 +30,7 @@ #include #include +#include #include "bsl_test_utils.h" @@ -197,6 +198,7 @@ static uint8_t test_256[32] = { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, void suiteSetUp(void) { + TEST_ASSERT_EQUAL_INT(0, BSL_HostDescriptors_Set(MockBPA_Agent_Descriptors(NULL))); BSL_openlog(); } @@ -286,7 +288,7 @@ void test_SeqWriter_flat(void) const uint8_t expect[] = { 0x01, 0x02, 0x03, 0x01, 0x02 }; TEST_ASSERT_EQUAL_MEMORY(expect, dest, sizeof(expect)); - BSL_FREE(dest); + BSL_free(dest); } // test vectors from RFC 4231 @@ -468,7 +470,7 @@ void test_encrypt(const char *plaintext_in, const char *keyid) res = BSL_Cipher_Deinit(&ctx); TEST_ASSERT_EQUAL(0, res); - BSL_FREE(ciphertext); + BSL_free(ciphertext); } /** @@ -539,7 +541,7 @@ void test_decrypt(const char *plaintext_in, const char *keyid) TEST_ASSERT_EQUAL(0, res); TEST_ASSERT_EQUAL(0, BSL_SeqReader_Destroy(reader)); - BSL_FREE(plaintext); + BSL_free(plaintext); } TEST_RANGE(<6, 18, 1>) diff --git a/test/test_DefaultSecurityContext.c b/test/test_DefaultSecurityContext.c index b378308..4107c29 100644 --- a/test/test_DefaultSecurityContext.c +++ b/test/test_DefaultSecurityContext.c @@ -51,14 +51,14 @@ static BSL_TestContext_t LocalTestCtx; void suiteSetUp(void) { - BSL_openlog(); TEST_ASSERT_EQUAL_INT(0, BSL_HostDescriptors_Set(MockBPA_Agent_Descriptors(NULL))); + BSL_openlog(); } int suiteTearDown(int failures) { - BSL_HostDescriptors_Clear(); BSL_closelog(); + BSL_HostDescriptors_Clear(); return failures; } @@ -106,7 +106,7 @@ void test_RFC9173_AppendixA_Example1_BIB_Source(void) BIBTestContext_Init(&bib_test_context); BSL_TestUtils_InitBIB_AppendixA1(&bib_test_context, BSL_SECROLE_SOURCE, RFC9173_EXAMPLE_A1_KEY); - BSL_SecOutcome_t *sec_outcome = BSL_CALLOC(1, BSL_SecOutcome_Sizeof()); + BSL_SecOutcome_t *sec_outcome = BSL_calloc(1, BSL_SecOutcome_Sizeof()); BSL_SecOutcome_Init(sec_outcome, &bib_test_context.sec_oper, BSL_SecOutcome_Sizeof()); /// Confirm running BIB as source executes without error @@ -132,7 +132,7 @@ void test_RFC9173_AppendixA_Example1_BIB_Source(void) } BSL_SecOutcome_Deinit(sec_outcome); - BSL_FREE(sec_outcome); + BSL_free(sec_outcome); BIBTestContext_Deinit(&bib_test_context); } @@ -168,7 +168,7 @@ void test_RFC9173_AppendixA_Example2_BCB_Source(void) BCBTestContext_Init(&bcb_test_context); BSL_TestUtils_InitBCB_Appendix2(&bcb_test_context, BSL_SECROLE_SOURCE); - BSL_SecOutcome_t *outcome = BSL_CALLOC(1, BSL_SecOutcome_Sizeof()); + BSL_SecOutcome_t *outcome = BSL_calloc(1, BSL_SecOutcome_Sizeof()); BSL_SecOutcome_Init(outcome, &bcb_test_context.sec_oper, 10000); // Execute BCB as source, confirm result is 0 (success) @@ -205,7 +205,7 @@ void test_RFC9173_AppendixA_Example2_BCB_Source(void) TEST_ASSERT_EQUAL_MEMORY(ApxA2_Ciphertext, target_block->btsd, sizeof(ApxA2_Ciphertext)); BSL_SecOutcome_Deinit(outcome); - BSL_FREE(outcome); + BSL_free(outcome); BCBTestContext_Deinit(&bcb_test_context); } @@ -219,7 +219,7 @@ void test_RFC9173_AppendixA_Example2_BCB_Acceptor(void) BCBTestContext_Init(&bcb_test_context); BSL_TestUtils_InitBCB_Appendix2(&bcb_test_context, BSL_SECROLE_ACCEPTOR); - BSL_SecOutcome_t *outcome = BSL_CALLOC(1, BSL_SecOutcome_Sizeof()); + BSL_SecOutcome_t *outcome = BSL_calloc(1, BSL_SecOutcome_Sizeof()); BSL_SecOutcome_Init(outcome, &bcb_test_context.sec_oper, 10000); /// Confirm that BCB executes with SUCCESS @@ -246,7 +246,7 @@ void test_RFC9173_AppendixA_Example2_BCB_Acceptor(void) TEST_ASSERT_EQUAL_MEMORY(ApxA2_PayloadData, target_block->btsd, sizeof(ApxA2_PayloadData)); BSL_SecOutcome_Deinit(outcome); - BSL_FREE(outcome); + BSL_free(outcome); BCBTestContext_Deinit(&bcb_test_context); } @@ -311,7 +311,7 @@ void test_sec_source_keywrap(bool wrap, bool bib) 0, BSL_TestUtils_LoadBundleFromCBOR(&LocalTestCtx, RFC9173_TestVectors_AppendixA1.cbor_bundle_original)); mock_bpa_ctr_t *mock_bpa_ctr = &LocalTestCtx.mock_bpa_ctr; - BSL_SecOutcome_t *sec_outcome = BSL_CALLOC(1, BSL_SecOutcome_Sizeof()); + BSL_SecOutcome_t *sec_outcome = BSL_calloc(1, BSL_SecOutcome_Sizeof()); const BSL_SecResult_t *result; BIBTestContext bibcontext; BCBTestContext bcbcontext; @@ -459,7 +459,7 @@ void test_sec_source_keywrap(bool wrap, bool bib) BSL_Data_Deinit(&cek_data); BSL_Data_Deinit(&kek_data); BSL_Data_Deinit(&wrapped_key_data); - BSL_FREE(sec_outcome); + BSL_free(sec_outcome); BIBTestContext_Deinit(&bibcontext); BCBTestContext_Deinit(&bcbcontext); } @@ -526,7 +526,7 @@ void test_sec_accept_keyunwrap(bool bib) } mock_bpa_ctr_t *mock_bpa_ctr = &LocalTestCtx.mock_bpa_ctr; - BSL_SecOutcome_t *sec_outcome = BSL_CALLOC(1, BSL_SecOutcome_Sizeof()); + BSL_SecOutcome_t *sec_outcome = BSL_calloc(1, BSL_SecOutcome_Sizeof()); BIBTestContext bibcontext; BCBTestContext bcbcontext; BIBTestContext_Init(&bibcontext); @@ -615,7 +615,7 @@ void test_sec_accept_keyunwrap(bool bib) BSL_Data_Deinit(&wrapped_key_data); BSL_Data_Deinit(&result_data); BSL_Data_Deinit(&iv_data); - BSL_FREE(sec_outcome); + BSL_free(sec_outcome); BIBTestContext_Deinit(&bibcontext); BCBTestContext_Deinit(&bcbcontext); } diff --git a/test/test_DynamicMemCbs.c b/test/test_DynamicMemCbs.c new file mode 100644 index 0000000..75f26b3 --- /dev/null +++ b/test/test_DynamicMemCbs.c @@ -0,0 +1,224 @@ +/* + * Copyright (c) 2025-2026 The Johns Hopkins University Applied Physics + * Laboratory LLC. + * + * This file is part of the Bundle Protocol Security Library (BSL). + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * This work was performed for the Jet Propulsion Laboratory, California + * Institute of Technology, sponsored by the United States Government under + * the prime contract 80NM0018D0004 between the Caltech and NASA under + * subcontract 1700763. + */ +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "bsl_test_utils.h" + +static int malloc_cnt = 0; +static int realloc_cnt = 0; +static int calloc_cnt = 0; +static int free_cnt = 0; + +static BSL_SecParam_t param_aes_variant_128; +static BSL_SecParam_t param_use_wrap_key; +static BSL_SecParam_t param_test_bcb_key_correct; + +static BSL_TestContext_t LocalTestCtx = { 0 }; +static BSL_SecurityActionSet_t action_set = { 0 }; + +static void *malloc_test(size_t size) +{ + malloc_cnt++; + return malloc(size); +} + +static void *realloc_test(void *ptr, size_t size) +{ + realloc_cnt++; + return realloc(ptr, size); +} + +static void *calloc_test(size_t nmemb, size_t size) +{ + calloc_cnt++; + return calloc(nmemb, size); +} + +static void free_test(void *ptr) +{ + free_cnt++; + free(ptr); +} + +void suiteSetUp(void) +{ + BSL_HostDescriptors_t host_desc = MockBPA_Agent_Descriptors(NULL); + BSL_DynMemHostDescriptors_t dyn_mem_desc = { + .malloc_cb = malloc_test, + .realloc_cb = realloc_test, + .calloc_cb = calloc_test, + .free_cb = free_test, + }; + host_desc.dyn_mem_desc = dyn_mem_desc; + + TEST_ASSERT_EQUAL_INT(0, BSL_HostDescriptors_Set(host_desc)); + BSL_openlog(); +} + +int suiteTearDown(int failures) +{ + BSL_closelog(); + BSL_HostDescriptors_Clear(); + return failures; +} + +// manually call this to control dynamic mem callback tracking for test +void _setUp(void) +{ + setenv("BSL_TEST_LOCAL_IPN_EID", "ipn:2.1", 1); + memset(&LocalTestCtx, 0, sizeof(LocalTestCtx)); + TEST_ASSERT_EQUAL(0, BSL_API_InitLib(&LocalTestCtx.bsl)); + mock_bpa_ctr_init(&LocalTestCtx.mock_bpa_ctr); + memset(&action_set, 0, sizeof(action_set)); + + BSL_CryptoInit(); + + BSL_SecParam_Init(¶m_aes_variant_128); + BSL_SecParam_Init(¶m_use_wrap_key); + BSL_SecParam_Init(¶m_test_bcb_key_correct); + + /// Register the policy provider with some rules + BSL_PolicyDesc_t policy_desc = { 0 }; + policy_desc.user_data = BSL_calloc(1, sizeof(BSLP_PolicyProvider_t)); + policy_desc.query_fn = BSLP_QueryPolicy; + policy_desc.deinit_fn = BSLP_Deinit; + policy_desc.finalize_fn = BSLP_FinalizePolicy; + TEST_ASSERT_EQUAL(0, BSL_API_RegisterPolicyProvider(&LocalTestCtx.bsl, BSL_SAMPLE_PP_ID, policy_desc)); + + BSLP_PolicyProvider_t *policy = BSL_PolicyDict_get(LocalTestCtx.bsl.policy_reg, BSL_SAMPLE_PP_ID)->user_data; + + policy->pp_id = 1; + + BSL_SecParam_InitInt64(¶m_aes_variant_128, RFC9173_BCB_SECPARAM_AESVARIANT, RFC9173_BCB_AES_VARIANT_A128GCM); + BSL_SecParam_InitInt64(¶m_use_wrap_key, BSL_SECPARAM_USE_KEY_WRAP, 1); + BSL_SecParam_InitTextstr(¶m_test_bcb_key_correct, BSL_SECPARAM_TYPE_KEY_ID, RFC9173_EXAMPLE_A2_KEY); + + // BSL_32 + BSLP_PolicyPredicate_t *predicate_bsl_32a = &policy->predicates[policy->predicate_count++]; + BSLP_PolicyPredicate_Init(predicate_bsl_32a, BSL_POLICYLOCATION_CLOUT, BSL_TestUtils_GetEidPatternFromText("*:**"), + BSL_TestUtils_GetEidPatternFromText("*:**"), + BSL_TestUtils_GetEidPatternFromText("ipn:*.3.2")); + BSLP_PolicyRule_t *rule_bsl_32a = &policy->rules[policy->rule_count++]; + BSLP_PolicyRule_Init(rule_bsl_32a, "SOURCE BCB OVER PAYLOAD AT CLOUT FILTER(DEST=ipn:3.2)", predicate_bsl_32a, 2, + BSL_SECROLE_SOURCE, BSL_SECBLOCKTYPE_BCB, BSL_BLOCK_TYPE_PAYLOAD, BSL_POLICYACTION_DROP_BLOCK); + BSLP_PolicyRule_CopyParam(rule_bsl_32a, ¶m_test_bcb_key_correct); + BSLP_PolicyRule_CopyParam(rule_bsl_32a, ¶m_aes_variant_128); + BSLP_PolicyRule_CopyParam(rule_bsl_32a, ¶m_use_wrap_key); + + BSLP_PolicyPredicate_t *predicate_bsl_32b = &policy->predicates[policy->predicate_count++]; + BSLP_PolicyPredicate_Init(predicate_bsl_32b, BSL_POLICYLOCATION_CLOUT, BSL_TestUtils_GetEidPatternFromText("*:**"), + BSL_TestUtils_GetEidPatternFromText("*:**"), + BSL_TestUtils_GetEidPatternFromText("ipn:*.3.2")); + BSLP_PolicyRule_t *rule_bsl_32b = &policy->rules[policy->rule_count++]; + BSLP_PolicyRule_Init(rule_bsl_32b, "SOURCE BCB OVER BIB AT CLOUT FILTER(DEST=ipn:3.2)", predicate_bsl_32b, 2, + BSL_SECROLE_SOURCE, BSL_SECBLOCKTYPE_BCB, BSL_BLOCK_TYPE_BIB, BSL_POLICYACTION_DROP_BLOCK); + BSLP_PolicyRule_CopyParam(rule_bsl_32b, ¶m_test_bcb_key_correct); + BSLP_PolicyRule_CopyParam(rule_bsl_32b, ¶m_aes_variant_128); + BSLP_PolicyRule_CopyParam(rule_bsl_32b, ¶m_use_wrap_key); + + /// Register the Security Context + BSL_TestUtils_SetupDefaultSecurityContext(&LocalTestCtx.bsl); +} + +// manually call this to control dynamic mem callback tracking for test +void _tearDown(void) +{ + BSL_SecurityActionSet_Deinit(&action_set); + mock_bpa_ctr_deinit(&LocalTestCtx.mock_bpa_ctr); + BSL_CryptoDeinit(); + TEST_ASSERT_EQUAL(0, BSL_API_DeinitLib(&LocalTestCtx.bsl)); + + BSL_SecParam_Deinit(¶m_aes_variant_128); + BSL_SecParam_Deinit(¶m_use_wrap_key); + BSL_SecParam_Deinit(¶m_test_bcb_key_correct); +} + +// Test BSL 32 with user-defined dyn mem cbs +void test_dyn_mem_cbs_BSL_32(void) +{ + _setUp(); + + BSL_PrimaryBlock_t primary_block; + BSL_SecurityResponseSet_t response_set = { 0 }; + BSL_CanonicalBlock_t res_blk; + int query_result = -1; + int apply_result = -1; + + TEST_ASSERT_EQUAL(0, + BSL_TestUtils_LoadBundleFromCBOR(&LocalTestCtx, RFC9173_TestVectors_AppendixA1.cbor_bundle_bib)); + + int res = BSL_TestUtils_ModifyEIDs(&LocalTestCtx.mock_bpa_ctr.bundle_ref, NULL, "ipn:3.2", NULL); + BSL_LOG_INFO("EID MODIFICATION RESULT: %d", res); + + BSL_BundleCtx_GetBundleMetadata(&LocalTestCtx.mock_bpa_ctr.bundle_ref, &primary_block); + TEST_ASSERT_EQUAL(2, primary_block.block_count); + + TEST_ASSERT_EQUAL(0, BSL_BundleCtx_GetBlockMetadata(&LocalTestCtx.mock_bpa_ctr.bundle_ref, 2, &res_blk)); + TEST_ASSERT_EQUAL(11, res_blk.type_code); // should be a bib already + + query_result = BSL_API_QuerySecurity(&LocalTestCtx.bsl, &action_set, &LocalTestCtx.mock_bpa_ctr.bundle_ref, + BSL_POLICYLOCATION_CLOUT); + TEST_ASSERT_EQUAL(0, query_result); + TEST_ASSERT_EQUAL(2, BSL_SecurityActionSet_CountOperations(&action_set)); + + apply_result = + BSL_API_ApplySecurity(&LocalTestCtx.bsl, &response_set, &LocalTestCtx.mock_bpa_ctr.bundle_ref, &action_set); + TEST_ASSERT_EQUAL(0, apply_result); + + for (size_t i = 0; i < BSL_SecurityActionSet_CountActions(&action_set); i++) + { + const BSL_SecurityAction_t *act = BSL_SecurityActionSet_GetActionAtIndex(&action_set, i); + for (size_t j = 0; j < BSL_SecurityAction_CountSecOpers(act); j++) + { + TEST_ASSERT_EQUAL(BSL_SECOP_CONCLUSION_SUCCESS, + BSL_SecOper_GetConclusion(BSL_SecurityAction_GetSecOperAtIndex(act, j))); + } + } + BSL_PrimaryBlock_deinit(&primary_block); + + BSL_BundleCtx_GetBundleMetadata(&LocalTestCtx.mock_bpa_ctr.bundle_ref, &primary_block); + + TEST_ASSERT_EQUAL(4, primary_block.block_count); + TEST_ASSERT_EQUAL(0, BSL_BundleCtx_GetBlockMetadata(&LocalTestCtx.mock_bpa_ctr.bundle_ref, 2, &res_blk)); + TEST_ASSERT_EQUAL(11, res_blk.type_code); + TEST_ASSERT_EQUAL(0, BSL_BundleCtx_GetBlockMetadata(&LocalTestCtx.mock_bpa_ctr.bundle_ref, 3, &res_blk)); + TEST_ASSERT_EQUAL(12, res_blk.type_code); + TEST_ASSERT_EQUAL(0, BSL_BundleCtx_GetBlockMetadata(&LocalTestCtx.mock_bpa_ctr.bundle_ref, 4, &res_blk)); + TEST_ASSERT_EQUAL(12, res_blk.type_code); + + BSL_PrimaryBlock_deinit(&primary_block); + + _tearDown(); + + TEST_ASSERT_NOT_EQUAL(0, malloc_cnt); + TEST_ASSERT_NOT_EQUAL(0, realloc_cnt); + TEST_ASSERT_NOT_EQUAL(0, calloc_cnt); + TEST_ASSERT_NOT_EQUAL(0, free_cnt); +} diff --git a/test/test_MockBPA_Codecs.c b/test/test_MockBPA_Codecs.c index 30a9ddf..7c0f821 100644 --- a/test/test_MockBPA_Codecs.c +++ b/test/test_MockBPA_Codecs.c @@ -50,14 +50,14 @@ static void printencoded(const uint8_t *pEncoded, size_t nLen) void suiteSetUp(void) { - BSL_openlog(); TEST_ASSERT_EQUAL_INT(0, BSL_HostDescriptors_Set(MockBPA_Agent_Descriptors(NULL))); + BSL_openlog(); } int suiteTearDown(int failures) { - BSL_HostDescriptors_Clear(); BSL_closelog(); + BSL_HostDescriptors_Clear(); return failures; } @@ -66,7 +66,7 @@ void setUp(void) TEST_ASSERT_EQUAL(0, BSL_API_InitLib(&bsl)); buf.len = 10000; - buf.ptr = BSL_MALLOC(buf.len); + buf.ptr = BSL_malloc(buf.len); TEST_ASSERT_NOT_NULL(buf.ptr); QCBOREncode_Init(&encoder, buf); } @@ -75,7 +75,7 @@ void tearDown(void) { if (buf.ptr) { - BSL_FREE(buf.ptr); + BSL_free(buf.ptr); } buf = NULLUsefulBuf; @@ -191,7 +191,7 @@ void test_bsl_mock_encode_canonical(uint64_t crc_type, const char *expecthex) blk.blk_num = 45; blk.flags = 0; blk.crc_type = crc_type; - blk.btsd = BSL_MALLOC(dummy_size); + blk.btsd = BSL_malloc(dummy_size); blk.btsd_len = dummy_size; memcpy(blk.btsd, dummy_btsd, dummy_size); @@ -205,7 +205,7 @@ void test_bsl_mock_encode_canonical(uint64_t crc_type, const char *expecthex) TEST_ASSERT_EQUAL_INT(expect_data.len, encoded.len); TEST_ASSERT_EQUAL_MEMORY(expect_data.ptr, encoded.ptr, expect_data.len); - BSL_FREE(blk.btsd); + BSL_free(blk.btsd); BSL_Data_Deinit(&expect_data); string_clear(expect_text); } @@ -237,7 +237,7 @@ void test_bsl_mock_encode_bundle(void) blk->blk_num = 45; blk->flags = 0; blk->crc_type = 0; - blk->btsd = BSL_CALLOC(1, dummy_size); + blk->btsd = BSL_calloc(1, dummy_size); blk->btsd_len = dummy_size; memcpy(blk->btsd, dummy_btsd, dummy_size); } diff --git a/test/test_MockBPA_EID.c b/test/test_MockBPA_EID.c index 4bbac41..b9c58d0 100644 --- a/test/test_MockBPA_EID.c +++ b/test/test_MockBPA_EID.c @@ -29,14 +29,14 @@ void suiteSetUp(void) { - BSL_openlog(); TEST_ASSERT_EQUAL_INT(0, BSL_HostDescriptors_Set(MockBPA_Agent_Descriptors(NULL))); + BSL_openlog(); } int suiteTearDown(int failures) { - BSL_HostDescriptors_Clear(); BSL_closelog(); + BSL_HostDescriptors_Clear(); return failures; } diff --git a/test/test_PublicInterfaceImpl.c b/test/test_PublicInterfaceImpl.c index b616821..cf0c3b5 100644 --- a/test/test_PublicInterfaceImpl.c +++ b/test/test_PublicInterfaceImpl.c @@ -59,14 +59,14 @@ static BSL_TestPublInterfaceCtx_t ctx = { 0 }; void suiteSetUp(void) { - BSL_openlog(); TEST_ASSERT_EQUAL_INT(0, BSL_HostDescriptors_Set(MockBPA_Agent_Descriptors(NULL))); + BSL_openlog(); } int suiteTearDown(int failures) { - BSL_HostDescriptors_Clear(); BSL_closelog(); + BSL_HostDescriptors_Clear(); return failures; } @@ -128,7 +128,7 @@ void setUp(void) /// Register the policy provider with some rules BSL_PolicyDesc_t policy_desc = { 0 }; - policy_desc.user_data = BSL_CALLOC(1, sizeof(BSLP_PolicyProvider_t)); + policy_desc.user_data = BSL_calloc(1, sizeof(BSLP_PolicyProvider_t)); policy_desc.query_fn = BSLP_QueryPolicy; policy_desc.deinit_fn = BSLP_Deinit; policy_desc.finalize_fn = BSLP_FinalizePolicy; diff --git a/test/test_SamplePolicyProvider.c b/test/test_SamplePolicyProvider.c index 58f8888..b37c97e 100644 --- a/test/test_SamplePolicyProvider.c +++ b/test/test_SamplePolicyProvider.c @@ -40,14 +40,14 @@ static BSL_TestContext_t LocalTestCtx; void suiteSetUp(void) { - BSL_openlog(); TEST_ASSERT_EQUAL_INT(0, BSL_HostDescriptors_Set(MockBPA_Agent_Descriptors(NULL))); + BSL_openlog(); } int suiteTearDown(int failures) { - BSL_HostDescriptors_Clear(); BSL_closelog(); + BSL_HostDescriptors_Clear(); return failures; } diff --git a/test/test_mock_bpa_ctr.c b/test/test_mock_bpa_ctr.c index 4f6fe8a..53f3519 100644 --- a/test/test_mock_bpa_ctr.c +++ b/test/test_mock_bpa_ctr.c @@ -27,14 +27,14 @@ void suiteSetUp(void) { - BSL_openlog(); TEST_ASSERT_EQUAL_INT(0, BSL_HostDescriptors_Set(MockBPA_Agent_Descriptors(NULL))); + BSL_openlog(); } int suiteTearDown(int failures) { - BSL_HostDescriptors_Clear(); BSL_closelog(); + BSL_HostDescriptors_Clear(); return failures; }