diff --git a/projects/yxml/Dockerfile b/projects/yxml/Dockerfile new file mode 100644 index 000000000000..64860963259f --- /dev/null +++ b/projects/yxml/Dockerfile @@ -0,0 +1,22 @@ +# Copyright 2024 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. +# +################################################################################ + +FROM gcr.io/oss-fuzz-base/base-builder +RUN apt-get update && apt-get install -y build-essential autoconf automake libtool + +RUN git clone https://github.com/JulStrat/yxml yxml +COPY *_fuzzer.c *.sh $SRC/ +WORKDIR $SRC/yxml diff --git a/projects/yxml/build.sh b/projects/yxml/build.sh new file mode 100644 index 000000000000..2b874ba21494 --- /dev/null +++ b/projects/yxml/build.sh @@ -0,0 +1,28 @@ +#!/bin/bash -eu +# +# Copyright 2024 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. +# +################################################################################ + +# Build yxml project +$CC $CFLAGS -I$SRC/yxml -c yxml.c -o yxml.a + +# Build fuzzing harness +$CC $CFLAGS -I$SRC/yxml -c $SRC/yxml_fuzzer.c -o yxml_fuzzer.o +$CXX $CXXFLAGS $LIB_FUZZING_ENGINE yxml_fuzzer.o \ + -o $OUT/yxml_fuzzer yxml.a + +# Create seed corpus +zip -rj $OUT/yxml_fuzzer_seed_corpus.zip $SRC/yxml/test/*.xml diff --git a/projects/yxml/project.yaml b/projects/yxml/project.yaml new file mode 100644 index 000000000000..3901c94cff31 --- /dev/null +++ b/projects/yxml/project.yaml @@ -0,0 +1,6 @@ +homepage: "https://github.com/JulStrat/yxml" +main_repo: "https://github.com/JulStrat/yxml.git" +language: c +vendor_ccs: +- "david@adalogics.com" +- "arthur.chan@adalogics.com" diff --git a/projects/yxml/yxml_fuzzer.c b/projects/yxml/yxml_fuzzer.c new file mode 100644 index 000000000000..7f3c25597ee1 --- /dev/null +++ b/projects/yxml/yxml_fuzzer.c @@ -0,0 +1,37 @@ +/* Copyright 2024 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 +#include + +#include "yxml.h" + +#define BUFFER_SIZE 4096 + +int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { + // Initialise YXML object + void *buf = malloc(BUFFER_SIZE); + yxml_t xml; + yxml_init(&xml, buf, BUFFER_SIZE); + + // Parse fuzzing data with YXML + for (int i = 0; i < size; i++) { + yxml_parse(&xml, data[i]); + } + + // Clean object + yxml_eof(&xml); + free(buf); + return 0; +}