From: Joseph Sutton Date: Wed, 27 Oct 2021 06:18:20 +0000 (+1300) Subject: CVE-2020-25722 pytest: Raise an error when adding a dynamic test that would overwrite... X-Git-Tag: ldb-2.5.0~167 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=deccd0dc5e41a86722e41883bb8788f70797aa5f;p=thirdparty%2Fsamba.git CVE-2020-25722 pytest: Raise an error when adding a dynamic test that would overwrite an existing test BUG: https://bugzilla.samba.org/show_bug.cgi?id=14753 Signed-off-by: Joseph Sutton Reviewed-by: Andrew Bartlett --- diff --git a/python/samba/tests/__init__.py b/python/samba/tests/__init__.py index ab366c7ed30..6d4993ac255 100644 --- a/python/samba/tests/__init__.py +++ b/python/samba/tests/__init__.py @@ -99,7 +99,10 @@ class TestCase(unittest.TestCase): def fn(self): getattr(self, "_%s_with_args" % fnname)(*args) fn.__doc__ = doc - setattr(cls, "%s_%s" % (fnname, suffix), fn) + attr = "%s_%s" % (fnname, suffix) + if hasattr(cls, attr): + raise RuntimeError(f"Dynamic test {attr} already exists!") + setattr(cls, attr, fn) @classmethod def setUpDynamicTestCases(cls):