SFT-6727: fixed dangling pointer warning for stack dummies
What changed, and why it matters
This commit suppresses a compiler warning about using the address of a short-lived local variable to track the top of the program's stack. The underlying code behavior is unchanged; only the warning is silenced. There is no direct security fix here, though the pattern itself is a known, long-standing MicroPython idiom for estimating stack usage.
No immediate action required. Treat as routine build-compatibility maintenance. If reviewing stack safety, audit whether `mp_stack_usage` estimates are used to enforce safe stack margins, because the proxy pointer becomes stale once the function returns.
Security signals we found
Compiler warning suppression for dangling-pointer diagnostic
Use of address of stack-local variable as stack pointer proxy
No bounds checking or memory safety change in the diff
Evidence from the diff
The patch adds #pragma GCC diagnostic warning "-Wdangling-pointer" around two uses of &stack_dummy in mp_stack_ctrl_init() and mp_stack_usage(). These functions store or compare the address of a local volatile int to approximate the current stack pointer. The pragma changes the diagnostic level for -Wdangling-pointer from error/default to warning, allowing compilation with newer GCC versions that flag this pattern. The functional code is identical before and after; version.txt is bumped from 2.3.10 to 2.4.0.
Changed components
MicroPython stack controller (extmod/trezor-firmware/vendor/micropython/py/stackctrl.c)MicroPython stack controller (py/stackctrl.c)Firmware version metadata (version.txt)Inspect captured patch +5 / −1
diff --git a/extmod/trezor-firmware/vendor/micropython/py/stackctrl.c b/extmod/trezor-firmware/vendor/micropython/py/stackctrl.c
index c2f3adb..394b406 100644
--- a/extmod/trezor-firmware/vendor/micropython/py/stackctrl.c
+++ b/extmod/trezor-firmware/vendor/micropython/py/stackctrl.c
@@ -29,6 +29,7 @@
void mp_stack_ctrl_init(void) {
volatile int stack_dummy;
+#pragma GCC diagnostic warning "-Wdangling-pointer"
MP_STATE_THREAD(stack_top) = (char *)&stack_dummy;
}
@@ -39,6 +40,7 @@ void mp_stack_set_top(void *top) {
mp_uint_t mp_stack_usage(void) {
// Assumes descending stack
volatile int stack_dummy;
+#pragma GCC diagnostic warning "-Wdangling-pointer"
return MP_STATE_THREAD(stack_top) - (char *)&stack_dummy;
}
diff --git a/py/stackctrl.c b/py/stackctrl.c
index c2f3adb..394b406 100644
--- a/py/stackctrl.c
+++ b/py/stackctrl.c
@@ -29,6 +29,7 @@
void mp_stack_ctrl_init(void) {
volatile int stack_dummy;
+#pragma GCC diagnostic warning "-Wdangling-pointer"
MP_STATE_THREAD(stack_top) = (char *)&stack_dummy;
}
@@ -39,6 +40,7 @@ void mp_stack_set_top(void *top) {
mp_uint_t mp_stack_usage(void) {
// Assumes descending stack
volatile int stack_dummy;
+#pragma GCC diagnostic warning "-Wdangling-pointer"
return MP_STATE_THREAD(stack_top) - (char *)&stack_dummy;
}
diff --git a/version.txt b/version.txt
index 9fa5f12..197c4d5 100644
--- a/version.txt
+++ b/version.txt
@@ -1 +1 @@
-2.3.10
+2.4.0
Why this scored 18/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.