diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-12-20 07:08:27 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-12-20 07:08:27 +0400 |
commit | 3c9f50204961b7fa8f6de259fa36deb24696a918 (patch) | |
tree | 50ca581a1ec01e56fee18ea37b4ae13eaba44e9f | |
parent | 3bc3e178b368d70856b951dc48049a1a35039f31 (diff) |
py api: be more strict with boolean assignment, only accept 0 or 1, True/False. Would allow any nonzero value.
-rw-r--r-- | source/blender/python/intern/bpy_rna.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index 55983c73895..b70e855d332 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -1510,12 +1510,18 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyOb /* prefer not to have an exception here * however so many poll functions return None or a valid Object. * its a hassle to convert these into a bool before returning, */ - if (RNA_property_flag(prop) & PROP_OUTPUT) + if (RNA_property_flag(prop) & PROP_OUTPUT) { param = PyObject_IsTrue(value); - else + } + else { param = PyLong_AsLong(value); - if (param < 0) { + if (UNLIKELY(param & ~1)) { /* only accept 0/1 */ + param = -1; /* error out below */ + } + } + + if (param == -1) { PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s expected True/False or 0/1, not %.200s", error_prefix, RNA_struct_identifier(ptr->type), |