From 34be76a4d1b4852a2985761090c1f82fcba714d5 Mon Sep 17 00:00:00 2001 From: "Earle F. Philhower, III" Date: Sat, 14 Mar 2020 15:48:21 -0700 Subject: [PATCH] Abort if BearSSL stack allocation fails As found by @d-a-v, if the malloc() used to get the BearSSL stack does not succeed abort() immediately. --- cores/esp8266/StackThunk.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cores/esp8266/StackThunk.cpp b/cores/esp8266/StackThunk.cpp index 541cd440ff..4b708bcc6f 100644 --- a/cores/esp8266/StackThunk.cpp +++ b/cores/esp8266/StackThunk.cpp @@ -26,6 +26,9 @@ #include #include +#include +#include "pgmspace.h" +#include "debug.h" #include "StackThunk.h" #include @@ -46,6 +49,11 @@ void stack_thunk_add_ref() stack_thunk_refcnt++; if (stack_thunk_refcnt == 1) { stack_thunk_ptr = (uint32_t *)malloc(_stackSize * sizeof(uint32_t)); + if (!stack_thunk_ptr) { + // This is a fatal error, stop the sketch + DEBUGV("Unable to allocate BearSSL stack\n"); + abort(); + } stack_thunk_top = stack_thunk_ptr + _stackSize - 1; stack_thunk_save = NULL; stack_thunk_repaint();