From a383c476e6eb9271649a1560d042dd338d6fa3cb Mon Sep 17 00:00:00 2001 From: Ryan Harrison Date: Thu, 10 Feb 2022 10:41:24 -0500 Subject: [PATCH] Remove reference to protobuf internals from fuzzers (#4701) In newer versions of protobuf the Status building code has been made internal, so that embedders cannot build their own instances like is being done here. Changing this code to just use the .ok() method on the status object, since if the status is OK or not is what is actually being tested. This will make it easier in the future to update external/protobuf. --- test/fuzz/fuzz_test_util.cpp | 2 +- tools/fuzz/fuzz.cpp | 22 +++++----------------- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/test/fuzz/fuzz_test_util.cpp b/test/fuzz/fuzz_test_util.cpp index bf0a4ff5d..93c9c584d 100644 --- a/test/fuzz/fuzz_test_util.cpp +++ b/test/fuzz/fuzz_test_util.cpp @@ -149,7 +149,7 @@ void DumpTransformationsJson( json_options.add_whitespace = true; auto json_generation_status = google::protobuf::util::MessageToJsonString( transformations, &json_string, json_options); - if (json_generation_status == google::protobuf::util::Status::OK) { + if (json_generation_status.ok()) { std::ofstream transformations_json_file(filename); transformations_json_file << json_string; transformations_json_file.close(); diff --git a/tools/fuzz/fuzz.cpp b/tools/fuzz/fuzz.cpp index 306f9255b..ca6633a6c 100644 --- a/tools/fuzz/fuzz.cpp +++ b/tools/fuzz/fuzz.cpp @@ -673,19 +673,6 @@ void DumpTransformationsBinary( transformations_file.close(); } -// The Chromium project applies the following patch to the protobuf library: -// -// source.chromium.org/chromium/chromium/src/+/main:third_party/protobuf/patches/0003-remove-static-initializers.patch -// -// This affects how Status objects must be constructed. This method provides a -// convenient way to get the OK status that works both with and without the -// patch. With the patch OK is a StatusPod, from which a Status can be -// constructed. Without the patch, OK is already a Status, and we harmlessly -// copy-construct the result from it. -google::protobuf::util::Status GetProtobufOkStatus() { - return google::protobuf::util::Status(google::protobuf::util::Status::OK); -} - // Dumps |transformations| to file |filename| in JSON format. Useful for // interactive debugging. void DumpTransformationsJson( @@ -696,7 +683,7 @@ void DumpTransformationsJson( json_options.add_whitespace = true; auto json_generation_status = google::protobuf::util::MessageToJsonString( transformations, &json_string, json_options); - if (json_generation_status == GetProtobufOkStatus()) { + if (json_generation_status.ok()) { std::ofstream transformations_json_file(filename); transformations_json_file << json_string; transformations_json_file.close(); @@ -747,8 +734,9 @@ int main(int argc, const char** argv) { std::string facts_json_string((std::istreambuf_iterator(facts_input)), std::istreambuf_iterator()); facts_input.close(); - if (GetProtobufOkStatus() != google::protobuf::util::JsonStringToMessage( - facts_json_string, &initial_facts)) { + if (!google::protobuf::util::JsonStringToMessage(facts_json_string, + &initial_facts) + .ok()) { spvtools::Error(FuzzDiagnostic, nullptr, {}, "Error reading facts data"); return 1; } @@ -828,7 +816,7 @@ int main(int argc, const char** argv) { json_options.add_whitespace = true; auto json_generation_status = google::protobuf::util::MessageToJsonString( transformations_applied, &json_string, json_options); - if (json_generation_status != GetProtobufOkStatus()) { + if (!json_generation_status.ok()) { spvtools::Error(FuzzDiagnostic, nullptr, {}, "Error writing out transformations in JSON format"); return 1;