Skip to content

Commit

Permalink
Abort if BearSSL stack allocation fails
Browse files Browse the repository at this point in the history
As found by @d-a-v, if the malloc() used to get the BearSSL stack does
not succeed abort() immediately.
  • Loading branch information
earlephilhower committed Mar 15, 2020
1 parent afb9921 commit 34be76a
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions cores/esp8266/StackThunk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@

#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include "pgmspace.h"
#include "debug.h"
#include "StackThunk.h"
#include <ets_sys.h>

Expand All @@ -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();
Expand Down

0 comments on commit 34be76a

Please sign in to comment.