Merge pull request #7504 from ejohnstown/generic-pool-fix

Generic Memory Pools Fix
This commit is contained in:
JacobBarthelmeh
2024-05-06 13:11:47 -06:00
committed by GitHub
4 changed files with 99 additions and 42 deletions
+14 -4
View File
@@ -656,11 +656,16 @@ int wc_LoadStaticMemory_ex(WOLFSSL_HEAP_HINT** pHint,
WOLFSSL_ENTER("wc_LoadStaticMemory_ex");
if (pHint == NULL || buf == NULL || listSz > WOLFMEM_MAX_BUCKETS
|| sizeList == NULL || distList == NULL) {
if (pHint == NULL || buf == NULL || sizeList == NULL || distList == NULL) {
return BAD_FUNC_ARG;
}
/* Cap the listSz to the actual number of items allocated in the list. */
if (listSz > WOLFMEM_MAX_BUCKETS) {
WOLFSSL_MSG("Truncating the list of memory buckets");
listSz = WOLFMEM_MAX_BUCKETS;
}
if ((sizeof(WOLFSSL_HEAP) + sizeof(WOLFSSL_HEAP_HINT)) > sz - idx) {
WOLFSSL_MSG("Not enough memory for partition tracking");
return BUFFER_E; /* not enough memory for structures */
@@ -761,11 +766,16 @@ int wolfSSL_StaticBufferSz_ex(unsigned int listSz,
WOLFSSL_ENTER("wolfSSL_StaticBufferSz_ex");
if (buffer == NULL || listSz > WOLFMEM_MAX_BUCKETS
|| sizeList == NULL || distList == NULL) {
if (buffer == NULL || sizeList == NULL || distList == NULL) {
return BAD_FUNC_ARG;
}
/* Cap the listSz to the actual number of items allocated in the list. */
if (listSz > WOLFMEM_MAX_BUCKETS) {
WOLFSSL_MSG("Truncating the list of memory buckets");
listSz = WOLFMEM_MAX_BUCKETS;
}
/* align pt */
while ((wc_ptr_t)pt % WOLFSSL_STATIC_ALIGN && pt < (buffer + sz)) {
pt++;
+8 -4
View File
@@ -16089,22 +16089,26 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t memory_test(void)
#ifdef WOLFSSL_STATIC_MEMORY
/* check macro settings */
if (sizeof(size)/sizeof(word32) != WOLFMEM_MAX_BUCKETS) {
if (sizeof(size)/sizeof(word32) != WOLFMEM_DEF_BUCKETS) {
return WC_TEST_RET_ENC_NC;
}
if (sizeof(dist)/sizeof(word32) != WOLFMEM_MAX_BUCKETS) {
if (sizeof(dist)/sizeof(word32) != WOLFMEM_DEF_BUCKETS) {
return WC_TEST_RET_ENC_NC;
}
for (i = 0; i < WOLFMEM_MAX_BUCKETS; i++) {
if (WOLFMEM_DEF_BUCKETS > WOLFMEM_MAX_BUCKETS) {
return WC_TEST_RET_ENC_NC;
}
for (i = 0; i < WOLFMEM_DEF_BUCKETS; i++) {
if ((size[i] % WOLFSSL_STATIC_ALIGN) != 0) {
/* each element in array should be divisible by alignment size */
return WC_TEST_RET_ENC_NC;
}
}
for (i = 1; i < WOLFMEM_MAX_BUCKETS; i++) {
for (i = 1; i < WOLFMEM_DEF_BUCKETS; i++) {
if (size[i - 1] >= size[i]) {
return WC_TEST_RET_ENC_NC; /* sizes should be in increasing order */
}