diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-01-24 06:38:34 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-01-24 06:38:34 +0300 |
commit | daa09a4a60086017e75c50c6de0b27fa51232e29 (patch) | |
tree | caa1a8c16bce7f1a4b89f5b9410e1868acc0f814 /source/blender/python | |
parent | 0097997911b8ed428e65f3fc7e46464575e71160 (diff) |
Raise an exception when registering classes with ID names which are too long. (related to bug ), found while looking into bug [#25776].
Diffstat (limited to 'source/blender/python')
-rw-r--r-- | source/blender/python/intern/bpy_rna.c | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index 8f745bc2756..e75d898d3aa 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -1071,17 +1071,19 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyOb case PROP_STRING: { const char *param; + Py_ssize_t param_size= 0; #ifdef USE_STRING_COERCE PyObject *value_coerce= NULL; int subtype= RNA_property_subtype(prop); if(ELEM3(subtype, PROP_FILEPATH, PROP_DIRPATH, PROP_FILENAME)) { + /* TODO, get size */ param= PyC_UnicodeAsByte(value, &value_coerce); } else { - param= _PyUnicode_AsString(value); + param= _PyUnicode_AsStringAndSize(value, ¶m_size); } #else // USE_STRING_COERCE - param= _PyUnicode_AsString(value); + param= _PyUnicode_AsStringAndSize(value, ¶m_size); #endif // USE_STRING_COERCE if (param==NULL) { @@ -1090,7 +1092,19 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyOb } else { if(data) *((char**)data)= (char *)param; /*XXX, this is suspect but needed for function calls, need to see if theres a better way */ - else RNA_property_string_set(ptr, prop, param); + else { + if(RNA_property_flag(prop) & PROP_NEVER_CLAMP) { + int param_size_max= RNA_property_string_maxlength(prop); + if(param_size > param_size_max) { + PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s only supports a string of length %d, found %d", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop), param_size, param_size_max); + return -1; + } +#ifdef USE_STRING_COERCE + Py_XDECREF(value_coerce); +#endif // USE_STRING_COERCE + } + RNA_property_string_set(ptr, prop, param); + } } #ifdef USE_STRING_COERCE Py_XDECREF(value_coerce); |