From 8a526848e23803df122ae1b6ec2176fe7af020e9 Mon Sep 17 00:00:00 2001 From: Arjun Singh <36335769+0x34d@users.noreply.github.com> Date: Wed, 24 Jan 2024 18:51:12 +0530 Subject: [PATCH] [brpc] ideal integration (#11531) Base PR https://github.com/apache/brpc/pull/2420 ; NOTE: I can't enable memory sanitizer due to ```log BAD BUILD: /tmp/not-out/tmpmptlk01q/fuzz_esp seems to have either startup crash or exit: /tmp/not-out/tmpmptlk01q/fuzz_esp -rss_limit_mb=2560 -timeout=25 -seed=1337 -runs=4 < /dev/null Uninitialized bytes in MemcmpInterceptorCommon at offset 15 inside [0x7030000000f0, 19) ==428==WARNING: MemorySanitizer: use-of-uninitialized-value #0 0x682b90 in __interceptor_memcmp /src/llvm-project/compiler-rt/lib/msan/../sanitizer_common/sanitizer_common_interceptors.inc:892:10 #1 0x7fa8ef4cf62a in google::protobuf::SimpleDescriptorDatabase::DescriptorIndex >::FindLastLessOrEqual(std::__cxx11::basic_string, std::allocator > const&) (/tmp/not-out/tmpmptlk01q/lib/libprotobuf.so.17+0x15062a) (BuildId: 64affeb0f489ae4bcea211ed99e1eca15ff97d68) #2 0x7fa8ef4d259f in google::protobuf::SimpleDescriptorDatabase::DescriptorIndex >::AddSymbol(std::__cxx11::basic_string, std::allocator > const&, std::pair) (/tmp/not-out/tmpmptlk01q/lib/libprotobuf.so.17+0x15359f) (BuildId: 64affeb0f489ae4bcea211ed99e1eca15ff97d68) #3 0x7fa8ef4d2a15 in google::protobuf::SimpleDescriptorDatabase::DescriptorIndex >::AddFile(google::protobuf::FileDescriptorProto const&, std::pair) (/tmp/not-out/tmpmptlk01q/lib/libprotobuf.so.17+0x153a15) (BuildId: 64affeb0f489ae4bcea211ed99e1eca15ff97d68) #4 0x7fa8ef4cebef in google::protobuf::EncodedDescriptorDatabase::Add(void const*, int) (/tmp/not-out/tmpmptlk01q/lib/libprotobuf.so.17+0x14fbef) (BuildId: 64affeb0f489ae4bcea211ed99e1eca15ff97d68) #5 0x7fa8ef499f43 in google::protobuf::DescriptorPool::InternalAddGeneratedFile(void const*, int) (/tmp/not-out/tmpmptlk01q/lib/libprotobuf.so.17+0x11af43) (BuildId: 64affeb0f489ae4bcea211ed99e1eca15ff97d68) #6 0x7fa8ef49281d in protobuf_google_2fprotobuf_2fapi_2eproto::AddDescriptorsImpl() (/tmp/not-out/tmpmptlk01q/lib/libprotobuf.so.17+0x11381d) (BuildId: 64affeb0f489ae4bcea211ed99e1eca15ff97d68) ``` Signed-off-by: Arjun Singh --- projects/brpc/CMakeLists.txt.patch | 30 ------------------ projects/brpc/Dockerfile | 8 ++--- projects/brpc/Fuzz_http.cpp | 33 -------------------- projects/brpc/Fuzz_json.cpp | 35 --------------------- projects/brpc/build.sh | 49 ------------------------------ projects/brpc/project.yaml | 3 +- 6 files changed, 4 insertions(+), 154 deletions(-) delete mode 100644 projects/brpc/CMakeLists.txt.patch delete mode 100644 projects/brpc/Fuzz_http.cpp delete mode 100644 projects/brpc/Fuzz_json.cpp delete mode 100644 projects/brpc/build.sh diff --git a/projects/brpc/CMakeLists.txt.patch b/projects/brpc/CMakeLists.txt.patch deleted file mode 100644 index 6a47f186f79a..000000000000 --- a/projects/brpc/CMakeLists.txt.patch +++ /dev/null @@ -1,30 +0,0 @@ ---- CMakeLists.txt 2022-10-29 16:48:38.253513165 +0530 -+++ CMakeLists.txt.backup 2022-10-29 16:52:45.751660599 +0530 -@@ -51,7 +51,7 @@ - message(FATAL_ERROR "Googletest is not available") - endif() - --set(CMAKE_CPP_FLAGS "${DEFINE_CLOCK_GETTIME} -DBRPC_WITH_GLOG=${WITH_GLOG_VAL} -DBRPC_WITH_RDMA=${WITH_RDMA_VAL} -DGFLAGS_NS=${GFLAGS_NS}") -+set(CMAKE_CPP_FLAGS "${CMAKE_CPP_FLAGS} ${DEFINE_CLOCK_GETTIME} -DBRPC_WITH_GLOG=${WITH_GLOG_VAL} -DBRPC_WITH_RDMA=${WITH_RDMA_VAL} -DGFLAGS_NS=${GFLAGS_NS}") - set(CMAKE_CPP_FLAGS "${CMAKE_CPP_FLAGS} -DBTHREAD_USE_FAST_PTHREAD_MUTEX -D__const__=__unused__ -D_GNU_SOURCE -DUSE_SYMBOLIZE -DNO_TCMALLOC -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -DUNIT_TEST -Dprivate=public -Dprotected=public -DBVAR_NOT_LINK_DEFAULT_VARIABLES -D__STRICT_ANSI__ -include ${PROJECT_SOURCE_DIR}/test/sstream_workaround.h") - set(CMAKE_CXX_FLAGS "${CMAKE_CPP_FLAGS} -g -O2 -pipe -Wall -W -fPIC -fstrict-aliasing -Wno-invalid-offsetof -Wno-unused-parameter -fno-omit-frame-pointer") - use_cxx11() -@@ -196,7 +196,7 @@ - set_property(TARGET ${BUTIL_DEBUG_LIB} PROPERTY POSITION_INDEPENDENT_CODE 1) - set_property(TARGET ${SOURCES_DEBUG_LIB} PROPERTY POSITION_INDEPENDENT_CODE 1) - --add_library(brpc-shared-debug SHARED $ -+add_library(brpc-shared-debug STATIC $ - $ - $) - # change the debug lib output dir to be different from the release output -@@ -252,3 +252,9 @@ - ${GPERFTOOLS_LIBRARIES}) - add_test(NAME ${BRPC_UT_WE} COMMAND ${BRPC_UT_WE}) - endforeach() -+ -+add_executable(Fuzz_json Fuzz_json.cpp $) -+target_link_libraries(Fuzz_json brpc-shared-debug ${LIB_FUZZING_ENGINE}) -+ -+add_executable(Fuzz_http Fuzz_http.cpp $) -+target_link_libraries(Fuzz_http brpc-shared-debug ${LIB_FUZZING_ENGINE}) diff --git a/projects/brpc/Dockerfile b/projects/brpc/Dockerfile index 45b03cce4415..9128ea13af67 100644 --- a/projects/brpc/Dockerfile +++ b/projects/brpc/Dockerfile @@ -15,10 +15,6 @@ ################################################################################ FROM gcr.io/oss-fuzz-base/base-builder RUN apt-get update && apt-get install -y cmake libgflags-dev libprotobuf-dev libprotoc-dev protobuf-compiler libleveldb-dev libgtest-dev libgoogle-perftools-dev libsnappy-dev -RUN git clone --depth 1 https://github.com/apache/incubator-brpc brpc -RUN git clone https://github.com/0x34d/oss-fuzz-bloat -COPY build.sh $SRC/ -COPY Fuzz_http.cpp $SRC/brpc/test/Fuzz_http.cpp -COPY Fuzz_json.cpp $SRC/brpc/test/Fuzz_json.cpp -COPY CMakeLists.txt.patch $SRC/brpc/test/CMakeLists.txt.patch +RUN git clone --depth 1 https://github.com/apache/brpc.git +RUN cp $SRC/brpc/test/fuzzing/oss-fuzz.sh $SRC/build.sh WORKDIR $SRC/brpc/ diff --git a/projects/brpc/Fuzz_http.cpp b/projects/brpc/Fuzz_http.cpp deleted file mode 100644 index 7575467abdba..000000000000 --- a/projects/brpc/Fuzz_http.cpp +++ /dev/null @@ -1,33 +0,0 @@ -/* Copyright 2022 Google LLC -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ -#include -#include "brpc/server.h" -#include "brpc/details/http_message.h" -#include "brpc/policy/http_rpc_protocol.h" -#include "echo.pb.h" - -#define kMinInputLength 5 -#define kMaxInputLength 1024 - -extern "C" int -LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) -{/*incubator-brpc/test/brpc_http_message_unittest.cpp*/ - - if (Size < kMinInputLength || Size > kMaxInputLength){ - return 0; - } - - brpc::HttpMessage http_message; - http_message.ParseFromArray((char *)Data, Size); - - return 0; -} diff --git a/projects/brpc/Fuzz_json.cpp b/projects/brpc/Fuzz_json.cpp deleted file mode 100644 index 907e830c3e49..000000000000 --- a/projects/brpc/Fuzz_json.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/* Copyright 2022 Google LLC -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ -#include -#include -#include "json2pb/json_to_pb.h" -#include "addressbook1.pb.h" - -#define kMinInputLength 5 -#define kMaxInputLength 1024 - -extern "C" int -LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) -{/*incubator-brpc/test/brpc_protobuf_json_unittest.cpp*/ - - if (Size < kMinInputLength || Size > kMaxInputLength){ - return 0; - } - - std::string error; - JsonContextBody data; - std::string input_data((char *)Data,Size); - - json2pb::JsonToProtoMessage(input_data, &data, &error); - - return 0; -} diff --git a/projects/brpc/build.sh b/projects/brpc/build.sh deleted file mode 100644 index 6596f1e1b296..000000000000 --- a/projects/brpc/build.sh +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/bash -eu -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -################################################################################ -pushd test/ -patch < CMakeLists.txt.patch -popd - -mkdir build && cd build - -cmake -DCMAKE_BUILD_TYPE=Debug -DBUILD_UNIT_TESTS=ON -DBUILD_SHARED_LIBS=OFF -DWITH_SNAPPY=ON \ --DCMAKE_C_COMPILER="$CC" -DCMAKE_CXX_COMPILER="$CXX" \ --DCMAKE_C_FLAGS="$CFLAGS" -DCMAKE_CXX_FLAGS="$CFLAGS" \ --DCMAKE_CPP_FLAGS="$CFLAGS" -DCMAKE_EXE_LINKER_FLAGS="$CFLAGS -Wl,-rpath,'\$ORIGIN/lib'" \ --DLIB_FUZZING_ENGINE="$LIB_FUZZING_ENGINE" \ -../ - -make -j$(nproc) Fuzz_json Fuzz_http - -pushd test/ -cp Fuzz_json $OUT/Fuzz_json -cp Fuzz_http $OUT/Fuzz_http -popd - -pushd $SRC/oss-fuzz-bloat/brpc/ -cp Fuzz_json_seed_corpus.zip $OUT/Fuzz_json_seed_corpus.zip -cp Fuzz_http_seed_corpus.zip $OUT/Fuzz_http_seed_corpus.zip -popd - -pushd /lib/x86_64-linux-gnu/ -mkdir $OUT/lib/ -cp libgflags* $OUT/lib/. -cp libprotobuf* $OUT/lib/. -cp libleveldb* $OUT/lib/. -cp libprotoc* $OUT/lib/. -cp libsnappy* $OUT/lib/. -popd diff --git a/projects/brpc/project.yaml b/projects/brpc/project.yaml index 987e954f1c1f..238ce0af9a0f 100644 --- a/projects/brpc/project.yaml +++ b/projects/brpc/project.yaml @@ -14,4 +14,5 @@ fuzzing_engines: - honggfuzz sanitizers: - address -main_repo: 'https://github.com/apache/incubator-brpc' + - undefined +main_repo: "https://github.com/apache/incubator-brpc"