diff options
author | Campbell Barton <ideasman42@gmail.com> | 2010-06-12 21:30:21 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2010-06-12 21:30:21 +0400 |
commit | 971e4be1081fb655f80d6d4065c734ccf625c987 (patch) | |
tree | be6d53d9712d5c51ef5e34f707c92274991c7439 /source/blender/blenkernel/intern/idprop.c | |
parent | c3c6fb2de28de350784db4730ed091da6b064198 (diff) |
modify my last commit to fix [#22486] add_actuator crashes when name is bigger than 32 chars
Throwing an exception if the strings too long means scripts need to be aware of string lengths and changing a string length in RNA can too easily break scripts.
Instead honor the string length in RNA_property_string_set()
Diffstat (limited to 'source/blender/blenkernel/intern/idprop.c')
-rw-r--r-- | source/blender/blenkernel/intern/idprop.c | 42 |
1 files changed, 36 insertions, 6 deletions
diff --git a/source/blender/blenkernel/intern/idprop.c b/source/blender/blenkernel/intern/idprop.c index 98b3522059c..2ccb33b088a 100644 --- a/source/blender/blenkernel/intern/idprop.c +++ b/source/blender/blenkernel/intern/idprop.c @@ -299,6 +299,34 @@ IDProperty *IDP_CopyArray(IDProperty *prop) /* ---------- String Type ------------ */ +IDProperty *IDP_NewString(const char *st, const char *name, int maxlen) +{ + IDProperty *prop = MEM_callocN(sizeof(IDProperty), "IDProperty string"); + + if (st == NULL) { + prop->data.pointer = MEM_callocN(DEFAULT_ALLOC_FOR_NULL_STRINGS, "id property string 1"); + prop->totallen = DEFAULT_ALLOC_FOR_NULL_STRINGS; + prop->len = 1; /*NULL string, has len of 1 to account for null byte.*/ + } + else { + int stlen = strlen(st); + + if(maxlen > 0 && maxlen < stlen) + stlen = maxlen; + + stlen++; /* null terminator '\0' */ + + prop->data.pointer = MEM_callocN(stlen, "id property string 2"); + prop->len = prop->totallen = stlen; + BLI_strncpy(prop->data.pointer, st, stlen); + } + + prop->type = IDP_STRING; + BLI_strncpy(prop->name, name, MAX_IDPROP_NAME); + + return prop; +} + IDProperty *IDP_CopyString(IDProperty *prop) { IDProperty *newp = idp_generic_copy(prop); @@ -312,14 +340,19 @@ IDProperty *IDP_CopyString(IDProperty *prop) } -void IDP_AssignString(IDProperty *prop, char *st) +void IDP_AssignString(IDProperty *prop, char *st, int maxlen) { int stlen; stlen = strlen(st); - IDP_ResizeArray(prop, stlen+1); /*make room for null byte :) */ - strcpy(prop->data.pointer, st); + if(maxlen > 0 && maxlen < stlen) + stlen= maxlen; + + stlen++; /* make room for null byte */ + + IDP_ResizeArray(prop, stlen); + BLI_strncpy(prop->data.pointer, st, stlen); } void IDP_ConcatStringC(IDProperty *prop, char *st) @@ -709,9 +742,6 @@ IDProperty *IDP_New(int type, IDPropertyTemplate val, const char *name) prop->type = type; BLI_strncpy(prop->name, name, MAX_IDPROP_NAME); - /*security null byte*/ - prop->name[MAX_IDPROP_NAME-1] = 0; - return prop; } |