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:
@@ -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);
|
||||
|
||||
@@ -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, ¶m_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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user