mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-22 22:38:08 +00:00
timer: Fix non-critical integer overflow (#129)
Every 4294967295 milliseconds (2 ^ 32 - 1), system_millis will overflow. This means that every 49.71 days, system_millis will reset to zero. Comparisons like `system_millis < (system_millis + 1)` would fail if the latter had overflown and the former had not. This is non-critical because the worst case is that one second could be skipped or the screen could lock early. This poses no threat to the exponential backoff used for protection against brute force.
This commit is contained in:
parent
15fcda21ce
commit
b4eaf7dbaf
@ -84,7 +84,7 @@ void layoutHome(void)
|
|||||||
oledRefresh();
|
oledRefresh();
|
||||||
|
|
||||||
// Reset lock screen timeout
|
// Reset lock screen timeout
|
||||||
system_millis_lock = system_millis + SCREEN_TIMEOUT_MILLIS;
|
system_millis_lock_start = system_millis;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *str_amount(uint64_t amnt, const char *abbr, char *buf, int len)
|
const char *str_amount(uint64_t amnt, const char *abbr, char *buf, int len)
|
||||||
|
@ -79,7 +79,7 @@ void check_lock_screen(void)
|
|||||||
|
|
||||||
// if homescreen is shown for longer than 10 minutes, lock too
|
// if homescreen is shown for longer than 10 minutes, lock too
|
||||||
if (layoutLast == layoutHome) {
|
if (layoutLast == layoutHome) {
|
||||||
if (system_millis >= system_millis_lock) {
|
if ((system_millis - system_millis_lock_start) >= 60000) {
|
||||||
// lock the screen
|
// lock the screen
|
||||||
session_clear(true);
|
session_clear(true);
|
||||||
layoutScreensaver();
|
layoutScreensaver();
|
||||||
|
@ -429,8 +429,9 @@ char usbTiny(char set)
|
|||||||
|
|
||||||
void usbSleep(uint32_t millis)
|
void usbSleep(uint32_t millis)
|
||||||
{
|
{
|
||||||
uint32_t end = system_millis + millis;
|
uint32_t start = system_millis;
|
||||||
while (end > system_millis) {
|
|
||||||
|
while ((system_millis - start) < millis) {
|
||||||
usbd_poll(usbd_dev);
|
usbd_poll(usbd_dev);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
2
timer.c
2
timer.c
@ -27,7 +27,7 @@
|
|||||||
volatile uint32_t system_millis;
|
volatile uint32_t system_millis;
|
||||||
|
|
||||||
/* Screen timeout */
|
/* Screen timeout */
|
||||||
uint32_t system_millis_lock;
|
uint32_t system_millis_lock_start;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialise the Cortex-M3 SysTick timer
|
* Initialise the Cortex-M3 SysTick timer
|
||||||
|
4
timer.h
4
timer.h
@ -24,9 +24,7 @@
|
|||||||
extern volatile uint32_t system_millis;
|
extern volatile uint32_t system_millis;
|
||||||
|
|
||||||
/* Screen timeout */
|
/* Screen timeout */
|
||||||
extern uint32_t system_millis_lock;
|
extern uint32_t system_millis_lock_start;
|
||||||
|
|
||||||
#define SCREEN_TIMEOUT_MILLIS (1000 * 60 * 10) /* 10 minutes */
|
|
||||||
|
|
||||||
void timer_init(void);
|
void timer_init(void);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user