Skip to content

Commit 21707c7

Browse files
authored
Merge pull request #595 from danielinux/fix_malloc_pkcs11_store
Fix malloc in pkcs11_store
2 parents be15345 + 6cdf76b commit 21707c7

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

options.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,7 @@ ifeq ($(WOLFCRYPT_TZ_PKCS11),1)
652652
CFLAGS+=-DCK_CALLABLE="__attribute__((cmse_nonsecure_entry))"
653653
CFLAGS+=-I$(WOLFBOOT_LIB_WOLFPKCS11)
654654
CFLAGS+=-DWP11_HASH_PIN_COST=3
655+
LDFLAGS+=--specs=nano.specs
655656
WOLFCRYPT_OBJS+=src/pkcs11_store.o
656657
WOLFCRYPT_OBJS+=src/pkcs11_callable.o
657658
WOLFCRYPT_OBJS+=$(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/pwdbased.o

src/pkcs11_store.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,16 @@ extern unsigned int _heap_size; /* From linker script: heap limit */
6666
void * _sbrk(unsigned int incr)
6767
{
6868
static unsigned char *heap = (unsigned char *)&_start_heap;
69-
static uint32_t heapsize = (uint32_t)(&_heap_size);
69+
static uint32_t heapsize = (uintptr_t)&_heap_size;
7070
void *old_heap = heap;
7171
if (((incr >> 2) << 2) != incr)
7272
incr = ((incr >> 2) + 1) << 2;
7373

74-
if (heap == NULL)
74+
if (heap == NULL) {
7575
heap = (unsigned char *)&_start_heap;
76-
else
76+
old_heap = heap;
77+
} else
7778
heap += incr;
78-
if (((uint32_t)heap - (uint32_t)(&_start_heap)) > heapsize) {
79-
heap -= incr;
80-
return NULL;
81-
}
8279
return old_heap;
8380
}
8481
#endif

0 commit comments

Comments
 (0)