Skip to content

Commit 777232c

Browse files
committed
esp8266: Disallow recursive calls to REPL.
Before this change, if REPL blocked executing some code, it was possible to still input new statememts and excuting them, all leading to weird, and portentially dangerous interaction. TODO: Current implementation may have issues processing input accumulated while REPL was blocked.
1 parent 3d4a535 commit 777232c

3 files changed

Lines changed: 19 additions & 2 deletions

File tree

esp8266/uart.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,17 @@ void mp_keyboard_interrupt(void);
234234

235235
int interrupt_char;
236236
void uart_task_handler(os_event_t *evt) {
237+
if (pyexec_repl_active) {
238+
// TODO: Just returning here isn't exactly right.
239+
// What really should be done is something like
240+
// enquing delayed event to itself, for another
241+
// chance to feed data to REPL. Otherwise, there
242+
// can be situation when buffer has bunch of data,
243+
// and sits unprocessed, because we consumed all
244+
// processing signals like this.
245+
return;
246+
}
247+
237248
int c, ret = 0;
238249
while ((c = ringbuf_get(&input_buf)) >= 0) {
239250
if (c == interrupt_char) {

lib/utils/pyexec.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,12 +277,17 @@ exec: ;
277277
}
278278
}
279279

280+
uint8_t pyexec_repl_active;
280281
int pyexec_event_repl_process_char(int c) {
282+
pyexec_repl_active = 1;
283+
int res;
281284
if (pyexec_mode_kind == PYEXEC_MODE_RAW_REPL) {
282-
return pyexec_raw_repl_process_char(c);
285+
res = pyexec_raw_repl_process_char(c);
283286
} else {
284-
return pyexec_friendly_repl_process_char(c);
287+
res = pyexec_friendly_repl_process_char(c);
285288
}
289+
pyexec_repl_active = 0;
290+
return res;
286291
}
287292

288293
#else // MICROPY_REPL_EVENT_DRIVEN

lib/utils/pyexec.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ int pyexec_file(const char *filename);
4242
int pyexec_frozen_module(const char *name);
4343
void pyexec_event_repl_init(void);
4444
int pyexec_event_repl_process_char(int c);
45+
extern uint8_t pyexec_repl_active;
4546

4647
MP_DECLARE_CONST_FUN_OBJ(pyb_set_repl_info_obj);
4748

0 commit comments

Comments
 (0)