[Bf-blender-cvs] [0a378b8ebce] master: Fix BKE_id_copy_ex() being able to 'return' garbage in copied ID.
Bastien Montagne
noreply at git.blender.org
Wed Jan 16 16:16:05 CET 2019
Commit: 0a378b8ebce46acfec405ca1403b126989e124ef
Author: Bastien Montagne
Date: Wed Jan 16 16:14:10 2019 +0100
Branches: master
https://developer.blender.org/rB0a378b8ebce46acfec405ca1403b126989e124ef
Fix BKE_id_copy_ex() being able to 'return' garbage in copied ID.
Reported/noted in D4178, it would return immediatly in case of NULL
source ID, without ensuring that return 'copied' ID was properly
initialized.
===================================================================
M source/blender/blenkernel/intern/library.c
===================================================================
diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c
index 0f33fc49ca2..e6c99e6a57b 100644
--- a/source/blender/blenkernel/intern/library.c
+++ b/source/blender/blenkernel/intern/library.c
@@ -566,10 +566,6 @@ bool BKE_id_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int flag, con
ID_IP /* Deprecated */
BLI_assert(test || (r_newid != NULL));
- /* Early output is source is NULL. */
- if (id == NULL) {
- return false;
- }
/* Make sure destination pointer is all good. */
if ((flag & LIB_ID_CREATE_NO_ALLOCATE) == 0) {
if (r_newid != NULL) {
@@ -578,11 +574,16 @@ bool BKE_id_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int flag, con
}
else {
if (r_newid != NULL && *r_newid != NULL) {
- /* Allow some garbage non-initialized memory to go in. */
+ /* Allow some garbage non-initialized memory to go in, and clean it up here. */
const size_t size = BKE_libblock_get_alloc_info(GS(id->name), NULL);
memset(*r_newid, 0, size);
}
}
+
+ /* Early output is source is NULL. */
+ if (id == NULL) {
+ return false;
+ }
if (ELEM(GS(id->name), LIB_ID_TYPES_NOCOPY)) {
return false;
}
More information about the Bf-blender-cvs
mailing list