8000 py/builtinimport: Raise exception on empty module name. · lvgl/lv_micropython@a7bc4d1 · GitHub
[go: up one dir, main page]

Skip to content

Commit a7bc4d1

Browse files
LeaNumworksdpgeorge
authored andcommitted
py/builtinimport: Raise exception on empty module name.
To prevent a crash returning MP_OBJ_NULL. A test is added for this case.
1 parent 6b3404f commit a7bc4d1

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

py/builtinimport.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,10 @@ mp_obj_t mp_builtin___import__(size_t n_args, const mp_obj_t *args) {
334334
mod_len = new_mod_l;
335335
}
336336

337+
if (mod_len == 0) {
338+
mp_raise_ValueError(NULL);
339+
}
340+
337341
// check if module already exists
338342
qstr module_name_qstr = mp_obj_str_get_qstr(module_name);
339343
mp_obj_t module_obj = mp_module_get(module_name_qstr);

tests/import/builtin_import.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
except TypeError:
1010
print('TypeError')
1111

12+
# module name should not be empty
13+
try:
14+
__import__("")
15+
except ValueError:
16+
print('ValueError')
17+
1218
# level argument should be non-negative
1319
try:
1420
__import__('xyz', None, None, None, -1)

0 commit comments

Comments
 (0)
0