]> granicus.if.org Git - python/commitdiff
bpo-31655: Validate keyword names in SimpleNamespace constructor. (#3909)
authorSerhiy Storchaka <storchaka@gmail.com>
Sat, 7 Oct 2017 19:59:35 +0000 (22:59 +0300)
committerGitHub <noreply@github.com>
Sat, 7 Oct 2017 19:59:35 +0000 (22:59 +0300)
Lib/test/test_types.py
Objects/namespaceobject.c

index 966ef6d8782575c48941edd18a92424a7be2ba22..28133a3560f3c5adbae851a129a79e07418a95fd 100644 (file)
@@ -1069,6 +1069,8 @@ class SimpleNamespaceTests(unittest.TestCase):
 
         with self.assertRaises(TypeError):
             types.SimpleNamespace(1, 2, 3)
+        with self.assertRaises(TypeError):
+            types.SimpleNamespace(**{1: 2})
 
         self.assertEqual(len(ns1.__dict__), 0)
         self.assertEqual(vars(ns1), {})
index 6deca961a4f11796c4e9b0e8f6f34815c5b8b298..e5698e6378de60f556f96a2388e0f0fa98cf592e 100644 (file)
@@ -44,8 +44,12 @@ namespace_init(_PyNamespaceObject *ns, PyObject *args, PyObject *kwds)
         PyErr_Format(PyExc_TypeError, "no positional arguments expected");
         return -1;
     }
-    if (kwds == NULL)
+    if (kwds == NULL) {
         return 0;
+    }
+    if (!PyArg_ValidateKeywordArguments(kwds)) {
+        return -1;
+    }
     return PyDict_Update(ns->ns_dict, kwds);
 }