Skip to content

Commit 0868942

Browse files
committed
py: Check for valid file when creating lexer for execfile.
Addresses issue adafruit#1119.
1 parent 1b8e76b commit 0868942

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

py/builtinevex.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ STATIC mp_obj_t eval_exec_helper(mp_uint_t n_args, const mp_obj_t *args, mp_pars
134134
mp_lexer_t *lex;
135135
if (MICROPY_PY_BUILTINS_EXECFILE && parse_input_kind == MP_PARSE_SINGLE_INPUT) {
136136
lex = mp_lexer_new_from_file(str);
137+
if (lex == NULL) {
138+
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError, "could not open file '%s'", str));
139+
}
137140
parse_input_kind = MP_PARSE_FILE_INPUT;
138141
} else {
139142
lex = mp_lexer_new_from_str_len(MP_QSTR__lt_string_gt_, str, str_len, 0);

0 commit comments

Comments
 (0)