aboutsummaryrefslogtreecommitdiffhomepage
path: root/projects/xmlpull
diff options
context:
space:
mode:
authorGravatar psy <patrice.salathe@code-intelligence.com>2022-04-26 09:13:29 +0200
committerGravatar GitHub <noreply@github.com>2022-04-26 17:13:29 +1000
commit184c04b70d04638b8db1c1e7353a902cae8a85cc (patch)
tree080f2fcf09ef782a2ec065c3cfe6fe606113f82b /projects/xmlpull
parent7a0502fb71bb74b2f8ec716fd40c84427cbe5b6f (diff)
Initial integration (#7611)
Diffstat (limited to 'projects/xmlpull')
-rw-r--r--projects/xmlpull/Dockerfile37
-rw-r--r--projects/xmlpull/XmlFuzzer.java36
-rwxr-xr-xprojects/xmlpull/build.sh96
-rw-r--r--projects/xmlpull/project.yaml13
4 files changed, 182 insertions, 0 deletions
diff --git a/projects/xmlpull/Dockerfile b/projects/xmlpull/Dockerfile
new file mode 100644
index 00000000..01cb3867
--- /dev/null
+++ b/projects/xmlpull/Dockerfile
@@ -0,0 +1,37 @@
+# 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.
+#
+################################################################################
+
+FROM gcr.io/oss-fuzz-base/base-builder-jvm
+
+RUN curl -L https://downloads.apache.org/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.zip -o maven.zip && \
+unzip maven.zip -d $SRC/maven && \
+rm -rf maven.zip
+
+RUN git clone --depth 1 https://github.com/google/fuzzing && \
+ mv fuzzing/dictionaries/xml.dict $SRC/JoranFuzzer.dict && \
+ rm -rf fuzzing
+
+RUN git clone --depth 1 https://github.com/dvyukov/go-fuzz-corpus && \
+ zip -q $SRC/JoranFuzzer_seed_corpus.zip go-fuzz-corpus/xml/corpus/* && \
+ rm -rf go-fuzz-corpus
+
+ENV MVN $SRC/maven/apache-maven-3.6.3/bin/mvn
+
+RUN git clone --depth 1 https://github.com/xmlpull-org/xmlpull-api-v1 xmlpull
+
+COPY build.sh $SRC/
+COPY XmlFuzzer.java $SRC/
+WORKDIR $SRC/xmlpull \ No newline at end of file
diff --git a/projects/xmlpull/XmlFuzzer.java b/projects/xmlpull/XmlFuzzer.java
new file mode 100644
index 00000000..935151cc
--- /dev/null
+++ b/projects/xmlpull/XmlFuzzer.java
@@ -0,0 +1,36 @@
+import com.code_intelligence.jazzer.api.FuzzedDataProvider;
+
+import org.xmlpull.v1.XmlPullParserFactory;
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+import org.xmlpull.v1.XmlSerializer;
+
+import java.io.IOException;
+import java.io.StringReader;
+
+public class XmlFuzzer {
+ public static XmlPullParserFactory factoryNewInstance() throws XmlPullParserException {
+ String property = System.getProperty(XmlPullParserFactory.PROPERTY_NAME);
+ return XmlPullParserFactory.newInstance(
+ property,
+ null
+ );
+ }
+
+ public static void processDocument(XmlPullParser xpp) throws XmlPullParserException, IOException {
+ int eventType = xpp.getEventType();
+ do {
+ eventType = xpp.next();
+ } while (eventType != xpp.END_DOCUMENT);
+ }
+
+ public static void fuzzerTestOneInput(FuzzedDataProvider data) {
+ try {
+ XmlPullParserFactory factory = factoryNewInstance();
+ factory.setNamespaceAware(true);
+ XmlPullParser xpp = factory.newPullParser();
+ xpp.setInput(new StringReader(data.consumeRemainingAsString()));
+ processDocument(xpp);
+ } catch (XmlPullParserException | IOException e) { }
+ }
+}
diff --git a/projects/xmlpull/build.sh b/projects/xmlpull/build.sh
new file mode 100755
index 00000000..93f369e2
--- /dev/null
+++ b/projects/xmlpull/build.sh
@@ -0,0 +1,96 @@
+#!/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.
+#
+################################################################################
+
+mv $SRC/{*.zip,*.dict} $OUT
+
+cat > patch.diff <<- EOM
+diff --git a/pom.xml b/pom.xml
+index 3e29db9..c79e086 100644
+--- a/pom.xml 2022-04-14 17:14:14.830692400 +0200
++++ b/pom.xml 2022-04-14 17:33:25.535451222 +0200
+@@ -30,6 +30,8 @@
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
++ <maven.compiler.source>1.8</maven.compiler.source>
++ <maven.compiler.target>1.8</maven.compiler.target>
+ </properties>
+
+ <dependencies>
+@@ -56,19 +58,6 @@
+ </goals>
+ </execution>
+ </executions>
+- </plugin>
+- <plugin>
+- <groupId>org.apache.maven.plugins</groupId>
+- <artifactId>maven-javadoc-plugin</artifactId>
+- <version>2.9.1</version>
+- <executions>
+- <execution>
+- <id>attach-javadocs</id>
+- <goals>
+- <goal>jar</goal>
+- </goals>
+- </execution>
+- </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+EOM
+
+git apply patch.diff
+
+
+# Use standard apache structure
+mkdir src/main
+mv src/java src/main/
+rm -r src/main/java/tests
+
+MAVEN_ARGS="-Djavac.src.version=15 -Djavac.target.version=15 -DskipTests"
+$MVN package $MAVEN_ARGS
+CURRENT_VERSION=$($MVN org.apache.maven.plugins:maven-help-plugin:3.2.0:evaluate \
+ -Dexpression=project.version -q -DforceStdout)
+cp "target/xmlpull-$CURRENT_VERSION.jar" "$OUT/xmlpull.jar"
+
+ALL_JARS="xmlpull.jar"
+
+# The classpath at build-time includes the project jars in $OUT as well as the
+# Jazzer API.
+BUILD_CLASSPATH=$(echo $ALL_JARS | xargs printf -- "$OUT/%s:"):$JAZZER_API_PATH
+
+# All .jar and .class files lie in the same directory as the fuzzer at runtime.
+RUNTIME_CLASSPATH=$(echo $ALL_JARS | xargs printf -- "\$this_dir/%s:"):\$this_dir
+
+for fuzzer in $(find $SRC -name '*Fuzzer.java'); do
+ fuzzer_basename=$(basename -s .java $fuzzer)
+ javac -cp $BUILD_CLASSPATH $fuzzer
+ cp $SRC/$fuzzer_basename.class $OUT/
+
+ # Create an execution wrapper that executes Jazzer with the correct arguments.
+ echo "#!/bin/sh
+# LLVMFuzzerTestOneInput for fuzzer detection.
+this_dir=\$(dirname \"\$0\")
+LD_LIBRARY_PATH=\"$JVM_LD_LIBRARY_PATH\":\$this_dir \
+\$this_dir/jazzer_driver --agent_path=\$this_dir/jazzer_agent_deploy.jar \
+--cp=$RUNTIME_CLASSPATH \
+--target_class=$fuzzer_basename \
+--jvm_args=\"-Xmx2048m\" \
+\$@" > $OUT/$fuzzer_basename
+ chmod u+x $OUT/$fuzzer_basename
+done \ No newline at end of file
diff --git a/projects/xmlpull/project.yaml b/projects/xmlpull/project.yaml
new file mode 100644
index 00000000..1dbb6a3c
--- /dev/null
+++ b/projects/xmlpull/project.yaml
@@ -0,0 +1,13 @@
+homepage: "https://github.com/xmlpull-org/xmlpull-api-v1"
+language: jvm
+primary_contact: "patrice.salathe@code-intelligence.com"
+auto_ccs:
+ - "wagner@code-intelligence.com"
+ - "yakdan@code-intelligence.com"
+ - "glendowne@code-intelligence.com"
+ - "patrice.salathe@code-intelligence.com"
+fuzzing_engines:
+ - libfuzzer
+sanitizers:
+ - address
+main_repo: "https://github.com/xmlpull-org/xmlpull-api-v1.git" \ No newline at end of file