• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #      http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 #
15 ################################################################################
16 */
17 #include "xerces_fuzz_common.h"
18 #include "xmlProtoConverter.h"
19 
20 #include "xercesc/framework/MemBufInputSource.hpp"
21 #include "xercesc/parsers/SAXParser.hpp"
22 #include "xercesc/util/OutOfMemoryException.hpp"
23 
24 #include "genfiles/xml.pb.h"
25 
26 #include "src/libfuzzer/libfuzzer_macro.h"
27 
28 #include <iostream>
29 
30 namespace {
31     protobuf_mutator::protobuf::LogSilencer log_silincer;
ignore(void * ctx,const char * msg,...)32     void ignore(void* ctx, const char* msg, ...) {}
33 
34     template <class T, class D>
MakeUnique(T * obj,D del)35     std::unique_ptr<T, D> MakeUnique(T* obj, D del) {
36     return {obj, del};
37     }
38 }
39 
40 using namespace xercesc_3_2;
41 
DEFINE_PROTO_FUZZER(const xmlProtoFuzzer::XmlDocument & xmlDocument)42 DEFINE_PROTO_FUZZER(const xmlProtoFuzzer::XmlDocument& xmlDocument) {
43     std::string xmlData = xmlProtoFuzzer::ProtoConverter().protoToString(xmlDocument);
44     parseInMemory((const uint8_t *)xmlData.c_str(), xmlData.size());
45 }
46