diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-09-15 15:49:36 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-09-15 15:49:36 +0400 |
commit | 9648c6016b35a72aa23395f5d200e342df16490b (patch) | |
tree | e9e5184d1039db277ff45ca162b621f2bad8b861 /source/blender/makesrna/intern | |
parent | 86d05b31446d8960679ece640089474afe5577d9 (diff) |
fix [#28658] python can assign non utf8 and crash because of string lenth limits.
add BLI_strncpy_utf8() which which ensures there are no partially copied UTF8 characters, limited by the buffer size.
Diffstat (limited to 'source/blender/makesrna/intern')
-rw-r--r-- | source/blender/makesrna/intern/makesrna.c | 14 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_ID.c | 2 |
2 files changed, 11 insertions, 5 deletions
diff --git a/source/blender/makesrna/intern/makesrna.c b/source/blender/makesrna/intern/makesrna.c index bc30210bfbb..23100fa8bd7 100644 --- a/source/blender/makesrna/intern/makesrna.c +++ b/source/blender/makesrna/intern/makesrna.c @@ -522,11 +522,14 @@ static char *rna_def_property_get_func(FILE *f, StructRNA *srna, PropertyRNA *pr fprintf(f, " %s(ptr, value);\n", manualfunc); } else { + const PropertySubType subtype= prop->subtype; + const char *string_copy_func= (subtype==PROP_FILEPATH || subtype==PROP_DIRPATH || subtype==PROP_FILENAME) ? "BLI_strncpy" : "BLI_strncpy_utf8"; + rna_print_data_get(f, dp); if(sprop->maxlength) - fprintf(f, " BLI_strncpy(value, data->%s, %d);\n", dp->dnaname, sprop->maxlength); + fprintf(f, " %s(value, data->%s, %d);\n", string_copy_func, dp->dnaname, sprop->maxlength); else - fprintf(f, " BLI_strncpy(value, data->%s, sizeof(data->%s));\n", dp->dnaname, dp->dnaname); + fprintf(f, " %s(value, data->%s, sizeof(data->%s));\n", string_copy_func, dp->dnaname, dp->dnaname); } fprintf(f, "}\n\n"); break; @@ -734,11 +737,14 @@ static char *rna_def_property_set_func(FILE *f, StructRNA *srna, PropertyRNA *pr fprintf(f, " %s(ptr, value);\n", manualfunc); } else { + const PropertySubType subtype= prop->subtype; + const char *string_copy_func= (subtype==PROP_FILEPATH || subtype==PROP_DIRPATH || subtype==PROP_FILENAME) ? "BLI_strncpy" : "BLI_strncpy_utf8"; + rna_print_data_get(f, dp); if(sprop->maxlength) - fprintf(f, " BLI_strncpy(data->%s, value, %d);\n", dp->dnaname, sprop->maxlength); + fprintf(f, " %s(data->%s, value, %d);\n", string_copy_func, dp->dnaname, sprop->maxlength); else - fprintf(f, " BLI_strncpy(data->%s, value, sizeof(data->%s));\n", dp->dnaname, dp->dnaname); + fprintf(f, " %s(data->%s, value, sizeof(data->%s));\n", string_copy_func, dp->dnaname, dp->dnaname); } fprintf(f, "}\n\n"); break; diff --git a/source/blender/makesrna/intern/rna_ID.c b/source/blender/makesrna/intern/rna_ID.c index 82217cdc3e4..05786cedeac 100644 --- a/source/blender/makesrna/intern/rna_ID.c +++ b/source/blender/makesrna/intern/rna_ID.c @@ -99,7 +99,7 @@ int rna_ID_name_length(PointerRNA *ptr) void rna_ID_name_set(PointerRNA *ptr, const char *value) { ID *id= (ID*)ptr->data; - BLI_strncpy(id->name+2, value, sizeof(id->name)-2); + BLI_strncpy_utf8(id->name+2, value, sizeof(id->name)-2); test_idbutton(id->name+2); } |