summaryrefslogtreecommitdiff
path: root/Python/getargs.c
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2010-04-24 18:21:17 +0000
committerBenjamin Peterson <benjamin@python.org>2010-04-24 18:21:17 +0000
commitbb5f3669f8ead9897f824bf97375348d120eb008 (patch)
tree26928cb336a46dfb9c2e2e4d56c495a4b6b3a31d /Python/getargs.c
parentdfe124a001209a9ecbd95969450e930ed3625664 (diff)
downloadcpython-bb5f3669f8ead9897f824bf97375348d120eb008.tar.gz
prevent the dict constructor from accepting non-string keyword args #8419
This adds PyArg_ValidateKeywordArguments, which checks that keyword arguments are all strings, using an optimized method if possible.
Diffstat (limited to 'Python/getargs.c')
-rw-r--r--Python/getargs.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/Python/getargs.c b/Python/getargs.c
index 17c5317d34..69f5018c4c 100644
--- a/Python/getargs.c
+++ b/Python/getargs.c
@@ -1607,6 +1607,21 @@ _PyArg_VaParseTupleAndKeywords_SizeT(PyObject *args,
return retval;
}
+int
+PyArg_ValidateKeywordArguments(PyObject *kwargs)
+{
+ if (!PyDict_CheckExact(kwargs)) {
+ PyErr_BadInternalCall();
+ return 0;
+ }
+ if (!_PyDict_HasOnlyStringKeys(kwargs)) {
+ PyErr_SetString(PyExc_TypeError,
+ "keyword arguments must be strings");
+ return 0;
+ }
+ return 1;
+}
+
#define IS_END_OF_FORMAT(c) (c == '\0' || c == ';' || c == ':')
static int