bugfix [#22486] add_actuator crashes when name is bigger than 32 chars

have pyrna raise an error on strings that are too long.
This commit is contained in:
2010-06-12 15:49:01 +00:00
parent 33b624cb5f
commit c3c6fb2de2
2 changed files with 11 additions and 4 deletions

View File

@@ -960,7 +960,8 @@ int RNA_property_int_clamp(PointerRNA *ptr, PropertyRNA *prop, int *value)
}
}
/* this is the max length including \0 terminator */
/* this is the max length including \0 terminator.
* -1 used when their is no maximum */
int RNA_property_string_maxlength(PropertyRNA *prop)
{
StringPropertyRNA *sprop= (StringPropertyRNA*)rna_ensure_property(prop);

View File

@@ -924,12 +924,18 @@ int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, ParameterList *parms, v
}
case PROP_STRING:
{
char *param = _PyUnicode_AsString(value);
Py_ssize_t param_len;
int param_maxlen= RNA_property_string_maxlength(prop) - 1;
char *param = _PyUnicode_AsStringAndSize(value, &param_len);
if (param==NULL) {
PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s expected a string type", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop));
return -1;
} else {
} else if (param_maxlen != -1 && param_len > param_maxlen) { /* -1 because it includes the \0 */
PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s string is length %d, expected maximum of %d", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop), (int)param_len, param_maxlen);
return -1;
}
else {
if(data) *((char**)data)= param;
else RNA_property_string_set(ptr, prop, param);
}