CMake: add WITH_STRSIZE_DEBUG option, RNA support
Support string size debug so it can be used for regular development. It works be writing values into strings, ensuring the buffer size given is actually available. Developers can use this with memory checking tools such as ASAN/valgrind to force an error when the value used for the size of a buffer is larger than the buffer. Resolve remaining issue with RNA using BLI_strncpy* in generated callback functions where the size argument didn't represent the size of the destination buffer. This is automatically enabled along with ASAN for the blender_developer.cmake configuration. Ref PR !107602.
This commit is contained in:
parent
0cf682f570
commit
7f8495c44b
@ -651,6 +651,12 @@ if(WIN32)
|
|||||||
set(CPACK_INSTALL_PREFIX ${CMAKE_GENERIC_PROGRAM_FILES}/${})
|
set(CPACK_INSTALL_PREFIX ${CMAKE_GENERIC_PROGRAM_FILES}/${})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
option(WITH_STRSIZE_DEBUG "\
|
||||||
|
Ensure string operations on fixed size buffers \
|
||||||
|
(works well with with \"WITH_COMPILER_ASAN\" & valgrind to detect incorrect buffer size arguments)"
|
||||||
|
OFF)
|
||||||
|
mark_as_advanced(WITH_STRSIZE_DEBUG)
|
||||||
|
|
||||||
# Compiler tool-chain.
|
# Compiler tool-chain.
|
||||||
if(UNIX)
|
if(UNIX)
|
||||||
if(CMAKE_COMPILER_IS_GNUCC)
|
if(CMAKE_COMPILER_IS_GNUCC)
|
||||||
|
@ -12,6 +12,7 @@ set(WITH_BUILDINFO OFF CACHE BOOL "" FORCE)
|
|||||||
# developer profile for now.
|
# developer profile for now.
|
||||||
if(NOT WIN32)
|
if(NOT WIN32)
|
||||||
set(WITH_COMPILER_ASAN ON CACHE BOOL "" FORCE)
|
set(WITH_COMPILER_ASAN ON CACHE BOOL "" FORCE)
|
||||||
|
set(WITH_STRSIZE_DEBUG ON CACHE BOOL "" FORCE)
|
||||||
endif()
|
endif()
|
||||||
set(WITH_CYCLES_NATIVE_ONLY ON CACHE BOOL "" FORCE)
|
set(WITH_CYCLES_NATIVE_ONLY ON CACHE BOOL "" FORCE)
|
||||||
set(WITH_DOC_MANPAGE OFF CACHE BOOL "" FORCE)
|
set(WITH_DOC_MANPAGE OFF CACHE BOOL "" FORCE)
|
||||||
|
@ -726,18 +726,13 @@ static char *rna_def_property_get_func(
|
|||||||
switch (prop->type) {
|
switch (prop->type) {
|
||||||
case PROP_STRING: {
|
case PROP_STRING: {
|
||||||
StringPropertyRNA *sprop = (StringPropertyRNA *)prop;
|
StringPropertyRNA *sprop = (StringPropertyRNA *)prop;
|
||||||
|
UNUSED_VARS_NDEBUG(sprop);
|
||||||
fprintf(f, "void %s(PointerRNA *ptr, char *value)\n", func);
|
fprintf(f, "void %s(PointerRNA *ptr, char *value)\n", func);
|
||||||
fprintf(f, "{\n");
|
fprintf(f, "{\n");
|
||||||
if (manualfunc) {
|
if (manualfunc) {
|
||||||
fprintf(f, " %s(ptr, value);\n", manualfunc);
|
fprintf(f, " %s(ptr, value);\n", manualfunc);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const PropertySubType subtype = prop->subtype;
|
|
||||||
const char *string_copy_func =
|
|
||||||
ELEM(subtype, PROP_FILEPATH, PROP_DIRPATH, PROP_FILENAME, PROP_BYTESTRING) ?
|
|
||||||
"BLI_strncpy" :
|
|
||||||
"BLI_strncpy_utf8";
|
|
||||||
|
|
||||||
rna_print_data_get(f, dp);
|
rna_print_data_get(f, dp);
|
||||||
|
|
||||||
if (dp->dnapointerlevel == 1) {
|
if (dp->dnapointerlevel == 1) {
|
||||||
@ -746,28 +741,24 @@ static char *rna_def_property_get_func(
|
|||||||
fprintf(f, " *value = '\\0';\n");
|
fprintf(f, " *value = '\\0';\n");
|
||||||
fprintf(f, " return;\n");
|
fprintf(f, " return;\n");
|
||||||
fprintf(f, " }\n");
|
fprintf(f, " }\n");
|
||||||
fprintf(f,
|
fprintf(f, " strcpy(value, data->%s);\n", dp->dnaname);
|
||||||
" %s(value, data->%s, strlen(data->%s) + 1);\n",
|
|
||||||
string_copy_func,
|
|
||||||
dp->dnaname,
|
|
||||||
dp->dnaname);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* Handle char array properties. */
|
/* Handle char array properties. */
|
||||||
|
|
||||||
|
#ifndef NDEBUG /* Assert lengths never exceed their maximum expected value. */
|
||||||
if (sprop->maxlength) {
|
if (sprop->maxlength) {
|
||||||
fprintf(f,
|
fprintf(f, " BLI_assert(strlen(data->%s) < %d);\n", dp->dnaname, sprop->maxlength);
|
||||||
" %s(value, data->%s, %d);\n",
|
|
||||||
string_copy_func,
|
|
||||||
dp->dnaname,
|
|
||||||
sprop->maxlength);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fprintf(f,
|
fprintf(f,
|
||||||
" %s(value, data->%s, sizeof(data->%s));\n",
|
" BLI_assert(strlen(data->%s) < sizeof(data->%s));\n",
|
||||||
string_copy_func,
|
|
||||||
dp->dnaname,
|
dp->dnaname,
|
||||||
dp->dnaname);
|
dp->dnaname);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
fprintf(f, " strcpy(value, data->%s);\n", dp->dnaname);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fprintf(f, "}\n\n");
|
fprintf(f, "}\n\n");
|
||||||
|
@ -26,6 +26,10 @@ if(HAVE_FEENABLEEXCEPT)
|
|||||||
add_definitions(-DHAVE_FEENABLEEXCEPT)
|
add_definitions(-DHAVE_FEENABLEEXCEPT)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(WITH_STRSIZE_DEBUG)
|
||||||
|
add_definitions(-DDEBUG_STRSIZE)
|
||||||
|
endif()
|
||||||
|
|
||||||
if(WITH_TBB)
|
if(WITH_TBB)
|
||||||
# Force TBB libraries to be in front of MKL (part of `OpenImageDenoise`), so
|
# Force TBB libraries to be in front of MKL (part of `OpenImageDenoise`), so
|
||||||
# that it is initialized before MKL and static library initialization order issues are avoided.
|
# that it is initialized before MKL and static library initialization order issues are avoided.
|
||||||
|
Loading…
Reference in New Issue
Block a user