Skip to content

Commit db75d2c

Browse files
Abort if BearSSL stack allocation fails (#7152)
As found by @d-a-v, if the malloc() used to get the BearSSL stack does not succeed, abort() immediately.
1 parent e252873 commit db75d2c

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

cores/esp8266/StackThunk.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626

2727
#include <stdint.h>
2828
#include <stdlib.h>
29+
#include <stdio.h>
30+
#include "pgmspace.h"
31+
#include "debug.h"
2932
#include "StackThunk.h"
3033
#include <ets_sys.h>
3134

@@ -46,6 +49,11 @@ void stack_thunk_add_ref()
4649
stack_thunk_refcnt++;
4750
if (stack_thunk_refcnt == 1) {
4851
stack_thunk_ptr = (uint32_t *)malloc(_stackSize * sizeof(uint32_t));
52+
if (!stack_thunk_ptr) {
53+
// This is a fatal error, stop the sketch
54+
DEBUGV("Unable to allocate BearSSL stack\n");
55+
abort();
56+
}
4957
stack_thunk_top = stack_thunk_ptr + _stackSize - 1;
5058
stack_thunk_save = NULL;
5159
stack_thunk_repaint();

0 commit comments

Comments
 (0)