Skip to content
This repository was archived by the owner on Jun 30, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ option (WITH_UNWIND "Enable libunwind support" ON)

cmake_dependent_option (WITH_GMOCK "Use Google Mock" ON WITH_GTEST OFF)

set (WITH_FUZZING none CACHE STRING "Fuzzing engine")
set_property (CACHE WITH_FUZZING PROPERTY STRINGS none libfuzzer ossfuzz)

if (NOT WITH_UNWIND)
set (CMAKE_DISABLE_FIND_PACKAGE_Unwind ON)
endif (NOT WITH_UNWIND)
Expand Down Expand Up @@ -748,6 +751,22 @@ endif (WITH_PKGCONFIG)

# Unit testing

if (NOT WITH_FUZZING STREQUAL "none")
add_executable (fuzz_demangle
src/fuzz_demangle.cc
)

if (WITH_FUZZING STREQUAL "ossfuzz")
set (LIB_FUZZING_ENGINE $ENV{LIB_FUZZING_ENGINE})
target_link_libraries (fuzz_demangle PRIVATE glog ${LIB_FUZZING_ENGINE})
elseif (WITH_FUZZING STREQUAL "libfuzzer")
target_compile_options (fuzz_demangle PRIVATE -fsanitize=fuzzer)
target_link_libraries (fuzz_demangle PRIVATE glog)
else (WITH_FUZZING STREQUAL "libfuzzer")
message (FATAL_ERROR "Unsupported fuzzing engine ${WITH_FUZZING}")
endif (WITH_FUZZING STREQUAL "ossfuzz")
endif (NOT WITH_FUZZING STREQUAL "none")

if (BUILD_TESTING)
add_library (glogtest STATIC
$<TARGET_OBJECTS:glog_internal>
Expand Down
32 changes: 32 additions & 0 deletions src/fuzz_demangle.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2023 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 <cstring>

#include "demangle.h"

extern "C" int LLVMFuzzerTestOneInput(const unsigned char *Data,
unsigned Size) {
if (Size >= 4095) {
return 0;
}
char Buffer[Size + 1];
std::memcpy(Buffer, Data, Size);
Buffer[Size] = 0;
char demangled[4096];
google::Demangle(Buffer, demangled, Size);
return 0;
}