diff options
author | Yonatan Goldschmidt <yon.goldschmidt@gmail.com> | 2019-12-17 22:40:40 +0200 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2020-01-12 13:09:23 +1100 |
commit | dce590c29dbefea253f4034c4bde3508f205364e (patch) | |
tree | f2b230fe4099570b38faff348d939238ec6abf9d | |
parent | df5c3bd97654c3719a62bb66627b4b538aa04b0f (diff) | |
download | micropython-dce590c29dbefea253f4034c4bde3508f205364e.tar.gz micropython-dce590c29dbefea253f4034c4bde3508f205364e.zip |
lib/mp-readline: Add an assert() to catch buffer overflows.
During readline development, this function may receive bad `pos` values.
It's easier to understand the assert() failing error than to have a "stack
smashing detected" message.
-rw-r--r-- | lib/mp-readline/readline.c | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/lib/mp-readline/readline.c b/lib/mp-readline/readline.c index 9d254d8cfe..1500873f69 100644 --- a/lib/mp-readline/readline.c +++ b/lib/mp-readline/readline.c @@ -74,6 +74,7 @@ STATIC void mp_hal_move_cursor_back(uint pos) { // snprintf needs space for the terminating null character int n = snprintf(&vt100_command[0], sizeof(vt100_command), "\x1b[%u", pos); if (n > 0) { + assert((unsigned)n < sizeof(vt100_command)); vt100_command[n] = 'D'; // replace null char mp_hal_stdout_tx_strn(vt100_command, n + 1); } |