OLD | NEW |
| (Empty) |
1 diff --git a/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_message.c
c b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_message.cc | |
2 index 9baaa35..0917537 100644 | |
3 --- a/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_message.cc | |
4 +++ b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_message.cc | |
5 @@ -2372,8 +2372,16 @@ GenerateClear(io::Printer* printer) { | |
6 // positions of two fields in the Message. | |
7 // ZR_ zeroes a non-empty range of fields via memset. | |
8 const char* macros = | |
9 + "#if defined(__clang__)\n" | |
10 + "#define ZR_HELPER_(f) \\\n" | |
11 + " _Pragma(\"clang diagnostic push\") \\\n" | |
12 + " _Pragma(\"clang diagnostic ignored \\\"-Winvalid-offsetof\\\"\") \\\n" | |
13 + " __builtin_offsetof($classname$, f) \\\n" | |
14 + " _Pragma(\"clang diagnostic pop\")\n" | |
15 + "#else\n" | |
16 "#define ZR_HELPER_(f) reinterpret_cast<char*>(\\\n" | |
17 - " &reinterpret_cast<$classname$*>(16)->f)\n\n" | |
18 + " &reinterpret_cast<$classname$*>(16)->f)\n" | |
19 + "#endif\n\n" | |
20 "#define ZR_(first, last) do {\\\n" | |
21 " ::memset(&first, 0,\\\n" | |
22 " ZR_HELPER_(last) - ZR_HELPER_(first) + sizeof(last));\\\n" | |
23 diff --git a/third_party/protobuf/src/google/protobuf/generated_message_reflecti
on.h b/third_party/protobuf/src/google/protobuf/generated_message_reflection.h | |
24 index 9ef7871..b26bbbc 100644 | |
25 --- a/third_party/protobuf/src/google/protobuf/generated_message_reflection.h | |
26 +++ b/third_party/protobuf/src/google/protobuf/generated_message_reflection.h | |
27 @@ -587,11 +587,22 @@ class LIBPROTOBUF_EXPORT GeneratedMessageReflection : publ
ic Reflection { | |
28 // just use zero, GCC complains about dereferencing a NULL pointer. We | |
29 // choose 16 rather than some other number just in case the compiler would | |
30 // be confused by an unaligned pointer. | |
31 +#if defined(__clang__) | |
32 +// For Clang we use __builtin_offsetof() and suppress the warning, | |
33 +// to avoid Control Flow Integrity and UBSan vptr sanitizers from | |
34 +// crashing while trying to validate the invalid reinterpet_casts. | |
35 +#define GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(TYPE, FIELD) \ | |
36 + _Pragma("clang diagnostic push") \ | |
37 + _Pragma("clang diagnostic ignored \"-Winvalid-offsetof\"") \ | |
38 + __builtin_offsetof(TYPE, FIELD) \ | |
39 + _Pragma("clang diagnostic pop") | |
40 +#else | |
41 #define GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(TYPE, FIELD) \ | |
42 static_cast<int>( \ | |
43 reinterpret_cast<const char*>( \ | |
44 &reinterpret_cast<const TYPE*>(16)->FIELD) - \ | |
45 reinterpret_cast<const char*>(16)) | |
46 +#endif | |
47 | |
48 #define PROTO2_GENERATED_DEFAULT_ONEOF_FIELD_OFFSET(ONEOF, FIELD) \ | |
49 static_cast<int>( \ | |
OLD | NEW |