From 068fa5a429a10c8c9d16e39166bf2778b6050550 Mon Sep 17 00:00:00 2001 From: "Earle F. Philhower, III" Date: Mon, 25 Feb 2019 15:28:04 -0800 Subject: [PATCH 1/2] Fix repaintable stack calculation Fixes #5794 as found by @mattbradford83 --- cores/esp8266/cont_util.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/cores/esp8266/cont_util.cpp b/cores/esp8266/cont_util.cpp index 66ebd06ac7..20fe46316e 100644 --- a/cores/esp8266/cont_util.cpp +++ b/cores/esp8266/cont_util.cpp @@ -73,12 +73,10 @@ void cont_repaint_stack(cont_t *cont) register uint32_t *sp asm("a1"); // Ensure 64 bytes adjacent to the current SP don't get touched to endure // we don't accidentally trounce over locals or IRQ temps. - uint32_t sp_safe = CONT_STACKSIZE/4 - ((sp - &cont->stack[0] - 64)/4); - // Fill stack with magic values - for(uint32_t pos = 0; pos < sp_safe; pos++) + for ( uint32_t *pos = sp - 16; pos != &cont->stack[0]; pos-- ) { - cont->stack[pos] = CONT_STACKGUARD; + *pos = CONT_STACKGUARD; } } From 54b9bdc7c202f6300f9bf31c0f2754dc3b7e3ddd Mon Sep 17 00:00:00 2001 From: "Earle F. Philhower, III" Date: Tue, 26 Feb 2019 08:43:00 -0800 Subject: [PATCH 2/2] Overwrite last word of stack as well Under-by-one error would not reset the absolute end of the stack, adjust comparison to fix. --- cores/esp8266/cont_util.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cores/esp8266/cont_util.cpp b/cores/esp8266/cont_util.cpp index 20fe46316e..d21a064e35 100644 --- a/cores/esp8266/cont_util.cpp +++ b/cores/esp8266/cont_util.cpp @@ -74,7 +74,7 @@ void cont_repaint_stack(cont_t *cont) // Ensure 64 bytes adjacent to the current SP don't get touched to endure // we don't accidentally trounce over locals or IRQ temps. // Fill stack with magic values - for ( uint32_t *pos = sp - 16; pos != &cont->stack[0]; pos-- ) + for ( uint32_t *pos = sp - 16; pos >= &cont->stack[0]; pos-- ) { *pos = CONT_STACKGUARD; }