[Bf-blender-cvs] [0a87fd4b929] lanpr-under-gp: Fix T81100: ccl::Node: ASan SEGV due to bad pointer

Ankit Meel noreply at git.blender.org
Fri Oct 2 07:40:25 CEST 2020


Commit: 0a87fd4b9293587fc9ad0f01d8003511965f5b3f
Author: Ankit Meel
Date:   Wed Sep 30 01:01:58 2020 +0530
Branches: lanpr-under-gp
https://developer.blender.org/rB0a87fd4b9293587fc9ad0f01d8003511965f5b3f

Fix T81100: ccl::Node: ASan SEGV due to bad pointer

`SOCKET_OFFSETOF` was added in the initial commit {rBec51175f1fd6c91d5}
when `offsetof` [1] was not supported well enough. GCC and LLVM
support it since C++17.

Other two changes: type and size check can be done without creating
an invalid address too.

[1] https://cppreference.com/w/cpp/types/offsetof

Reviewed By: campbellbarton, brecht

Maniphest Tasks: T81100

Differential Revision: https://developer.blender.org/D9042

===================================================================

M	intern/cycles/graph/node_type.h

===================================================================

diff --git a/intern/cycles/graph/node_type.h b/intern/cycles/graph/node_type.h
index 0d182945e16..69891e6a10a 100644
--- a/intern/cycles/graph/node_type.h
+++ b/intern/cycles/graph/node_type.h
@@ -165,12 +165,12 @@ struct NodeType {
 
 /* Sock Definition Macros */
 
-#define SOCKET_OFFSETOF(T, name) (((char *)&(((T *)1)->name)) - (char *)1)
-#define SOCKET_SIZEOF(T, name) (sizeof(((T *)1)->name))
+#define SOCKET_OFFSETOF(T, name) offsetof(T, name)
+#define SOCKET_SIZEOF(T, name) (sizeof(T::name))
 #define SOCKET_DEFINE(name, ui_name, default_value, datatype, TYPE, flags, ...) \
   { \
     static datatype defval = default_value; \
-    CHECK_TYPE(((T *)1)->name, datatype); \
+    CHECK_TYPE(T::name, datatype); \
     type->register_input(ustring(#name), \
                          ustring(ui_name), \
                          TYPE, \



More information about the Bf-blender-cvs mailing list