Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
CMakefiles edit
  • Loading branch information
Vincent Ulitzsch
Vincent Ulitzsch committed Apr 24, 2020
commit 1f43abf73470191baa05975d8da0cda69e0e0606
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,6 @@ tests/scripts/*.log
tests/scripts/*.trs
tests/test-suite.log
Testing/

# Vincent
build/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change should be kept private. Please could you remove it from the PR?

4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ add_subdirectory(src)
add_subdirectory(tests)
add_subdirectory(samples)

if (XERCES_BUILD_FUZZERS)
add_subdirectory(fuzzers)
endif()

# Display configuration summary
message(STATUS "")
message(STATUS "Xerces-C++ configuration summary")
Expand Down
8 changes: 8 additions & 0 deletions build_fuzzer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see this file being used anywhere. Does it really belong in the source tree?

If it does belong, could it go into the scripts subdirectory alongside the CI scripts?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not necessarily needed, but I thought it might be helpful if someone does not want to figure out the build options by themselves. Should it go into the scripts sub-directory or be completely removed?

set -e
rm -rf build
mkdir build
cd build
CC=clang CXX=clang++ CXXFLAGS="-std=c++14" cmake .. -DXERCES_BUILD_FUZZERS=1 -Wfatal-errors
CC=clang CXX=clang++ CXXFLAGS="-std=c++14" make -j8

101 changes: 101 additions & 0 deletions fuzzers/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# CMake build for xerces-c
#
# Written by Roger Leigh <rleigh@codelibre.net>
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You 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.

# Definitions required for building
add_definitions(
-DHAVE_CONFIG_H=1

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is necessary, I think target_compile_definitions would be more appropriate, rather than setting it globally.

)
# Search the project binary dir for config.h
include_directories(
${PROJECT_BINARY_DIR}
${PROJECT_SOURCE_DIR}/src
${PROJECT_BINARY_DIR}/src
${CMAKE_CURRENT_SOURCE_DIR}
)
set(EXTRA_DIST
src/DOM/Normalizer/expectedOutput
src/DOM/TypeInfo/data/combined.dtd
src/DOM/TypeInfo/data/combined.xml
src/DOM/TypeInfo/data/combined.xsd
src/DOM/TypeInfo/data/SecondSchema.xsd
src/DOM/TypeInfo/data/TypeInfo.dtd
src/DOM/TypeInfo/data/TypeInfo.xml
src/DOM/TypeInfo/data/TypeInfo.xsd
src/DOM/TypeInfo/data/TypeInfoJustDTD.xml
src/DOM/TypeInfo/data/TypeInfoNoDTD.xml
src/DOM/TypeInfo/data/TypeInfoNoDTD.xsd
src/XSTSHarness/regression
src/xinclude
)

macro(add_fuzzer_executable name)
add_executable(${name} ${ARGN})
target_link_libraries(${name} xerces-c)
target_compile_options(${name} PUBLIC -fsanitize=fuzzer)
target_link_libraries(${name} -fsanitize=fuzzer)
set_target_properties(${name} PROPERTIES FOLDER "Fuzzers")
endmacro()

add_fuzzer_executable(fuzz_parser_target
src/xerces_fuzz_common.cpp
src/parse_target.cpp

)

include(ExternalProject)

set(EXTERNAL_INSTALL_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/external)


ExternalProject_Add(libprotobuf-mutator
GIT_SHALLOW 1
GIT_REPOSITORY https://github.com/google/libprotobuf-mutator.git
CMAKE_ARGS -DCMAKE_BUILD_TYPE=Release -DLIB_PROTO_MUTATOR_DOWNLOAD_PROTOBUF=ON -DLIB_PROTO_MUTATOR_TESTING=false -DCMAKE_INSTALL_PREFIX=${EXTERNAL_INSTALL_LOCATION}
)

set(PROTOC_PATH /usr/local/bin/protoc) #${CMAKE_CURRENT_BINARY_DIR}/libprotobuf-mutator-prefix/src/libprotobuf-mutator-build/external.protobuf/bin/protoc)
#set(PROTOC_PATH ${CMAKE_CURRENT_BINARY_DIR}/libprotobuf-mutator-prefix/src/libprotobuf-mutator-build/external.protobuf/bin/protoc)

message(STATUS "### Vincent Debug: ${CMAKE_CURRENT_SOURCE_DIR} ${PROTOC_PATH} ${EXTERNAL_INSTALL_LOCATION} ${CMAKE_CURRENT_BINARY_DIR}/libprotobuf-mutator-prefix/src/libprotobuf-mutator-build/external.protobuf/src/external.protobuf-build/libprotobuf.a")

add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/genfiles ${CMAKE_CURRENT_BINARY_DIR}/genfiles/xml.pb.cc
DEPENDS libprotobuf-mutator
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src
COMMAND mkdir ${CMAKE_CURRENT_BINARY_DIR}/genfiles && ${PROTOC_PATH} xml.proto --cpp_out=${CMAKE_CURRENT_BINARY_DIR}/genfiles
)
add_custom_target(xml_proto_files ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/genfiles)



add_fuzzer_executable(fuzz_parser_target_proto
src/xerces_fuzz_common.cpp
src/parse_target_proto.cpp
src/xmlProtoConverter.cpp
${CMAKE_CURRENT_BINARY_DIR}/genfiles/xml.pb.cc
)
add_dependencies(fuzz_parser_target_proto xml_proto_files)
add_dependencies(fuzz_parser_target_proto libprotobuf-mutator)
target_include_directories(fuzz_parser_target_proto PUBLIC ${EXTERNAL_INSTALL_LOCATION}/include)
target_include_directories(fuzz_parser_target_proto PUBLIC ${EXTERNAL_INSTALL_LOCATION}/include/libprotobuf-mutator/)
target_include_directories(fuzz_parser_target_proto PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/genfiles)
target_link_libraries(fuzz_parser_target_proto ${EXTERNAL_INSTALL_LOCATION}/lib/libprotobuf-mutator-libfuzzer.a)
target_link_libraries(fuzz_parser_target_proto ${EXTERNAL_INSTALL_LOCATION}/lib/libprotobuf-mutator.a)
target_link_libraries(fuzz_parser_target_proto ${CMAKE_CURRENT_BINARY_DIR}/libprotobuf-mutator-prefix/src/libprotobuf-mutator-build/external.protobuf/src/external.protobuf-build/libprotobuf.a)

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
#include "xercesc/parsers/SAXParser.hpp"
#include "xercesc/util/OutOfMemoryException.hpp"

#include "genfiles/xml.pb.h"
#include "xml.pb.h"

#include "src/libfuzzer/libfuzzer_macro.h"
#include "libprotobuf-mutator/src/libfuzzer/libfuzzer_macro.h"

#include <iostream>

Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1272,6 +1272,10 @@ add_library(xerces-c
${libxerces_c_SOURCES}
${libxerces_c_RESOURCES})
target_link_libraries(xerces-c ${libxerces_c_DEPS})
if (XERCES_BUILD_FUZZERS)
target_compile_options(xerces-c PUBLIC -fsanitize=fuzzer-no-link)
target_link_libraries(xerces-c -fsanitize=fuzzer-no-link)
endif()
if(XERCES_USE_NETACCESSOR_CURL)
target_include_directories(xerces-c SYSTEM PRIVATE ${CURL_INCLUDE_DIRS})
endif()
Expand Down