[issue41993] Possible issues when remove not completely initialized module from sys.module

Serhiy Storchaka report at bugs.python.org
Sat Oct 10 06:51:27 EDT 2020


New submission from Serhiy Storchaka <storchaka+cpython at 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 <report at bugs.python.org>
<https://bugs.python.org/issue41993>
_______________________________________


More information about the Python-bugs-list mailing list