New submission from Serhiy Storchaka <storchaka+cpyt...@gmail.com>:

There are several issues in remove_module() in Python/import.c.

1. PyMapping_HasKey() is used to determine if the module was in sys.modules 
before removing it. But it can return 0 not only when the key is absent in the 
mapping, but also when some exceptions was raised during checking (including 
MemoryError, KeybordInterraption and RecursionError). The corresponding 
exception will be silenced and the module will be left in sys.modules.

2. If PyMapping_DelItem() fails, a RuntimeError is raised. It is chained with 
the exception raised in PyMapping_DelItem(), but the original exception, raised 
before calling remove_module() will be lost.

3. There is a possible race condition between PyMapping_HasKey() and 
PyMapping_DelItem().

----------
components: Interpreter Core
messages: 378382
nosy: brett.cannon, eric.snow, ncoghlan, serhiy.storchaka
priority: normal
severity: normal
status: open
title: Possible issues when remove not completely initialized module from 
sys.module
type: behavior
versions: Python 3.10, Python 3.8, Python 3.9

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue41993>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to