aboutsummaryrefslogtreecommitdiff
path: root/src/google/protobuf/compiler/cpp/cpp_enum_field.cc
diff options
context:
space:
mode:
authorPetr Prokhorenkov <prokhorenkov@gmail.com>2016-04-14 11:17:54 +0300
committerPetr Prokhorenkov <prokhorenkov@gmail.com>2016-04-21 09:27:33 +0300
commitf4f9aec52f5b4c46ff32fb9527229da081a14e11 (patch)
tree02d8ff141ad7e0228bfcf6b2f5ee1322c5df5fbd /src/google/protobuf/compiler/cpp/cpp_enum_field.cc
parent814685ca2cd9280ca401e1842fd6311440921a0a (diff)
downloadprotobuf-f4f9aec52f5b4c46ff32fb9527229da081a14e11.tar.gz
protobuf-f4f9aec52f5b4c46ff32fb9527229da081a14e11.tar.bz2
protobuf-f4f9aec52f5b4c46ff32fb9527229da081a14e11.zip
Fix bug with silent message corruption in LITE_RUNTIME.
A protobuf message will be corrupted in the following scenario: 1. Use LITE_RUNTIME. 2. Have an optional enum field following some other field. 3. Update protocol by adding new values to the enum. 4. Have an old client parse and serialize a message having enum field set to a value the client does not understand. 5. Field preceeding the enum is now corrupted. The bug is due to the fact that optimized fallthrough in parser code does not update variablle 'tag' when jumping to the parser code for the next field.
Diffstat (limited to 'src/google/protobuf/compiler/cpp/cpp_enum_field.cc')
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_enum_field.cc6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/google/protobuf/compiler/cpp/cpp_enum_field.cc b/src/google/protobuf/compiler/cpp/cpp_enum_field.cc
index 824e2205..06cb18d1 100644
--- a/src/google/protobuf/compiler/cpp/cpp_enum_field.cc
+++ b/src/google/protobuf/compiler/cpp/cpp_enum_field.cc
@@ -36,6 +36,7 @@
#include <google/protobuf/compiler/cpp/cpp_helpers.h>
#include <google/protobuf/io/printer.h>
#include <google/protobuf/stubs/strutil.h>
+#include <google/protobuf/wire_format.h>
namespace google {
namespace protobuf {
@@ -142,8 +143,9 @@ GenerateMergeFromCodedStream(io::Printer* printer) const {
} else {
printer->Print(
"} else {\n"
- " unknown_fields_stream.WriteVarint32(tag);\n"
- " unknown_fields_stream.WriteVarint32(value);\n");
+ " unknown_fields_stream.WriteVarint32($tag$);\n"
+ " unknown_fields_stream.WriteVarint32(value);\n",
+ "tag", SimpleItoa(internal::WireFormat::MakeTag(descriptor_)));
}
printer->Print(variables_,
"}\n");