Skip to content

Commit

Permalink
unirest-java: initial integration (#10943)
Browse files Browse the repository at this point in the history
Initial integration for project unirest-java.

Signed-off-by: Arthur Chan <[email protected]>
  • Loading branch information
arthurscchan authored Sep 14, 2023
1 parent 79b11b8 commit 868a94f
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 0 deletions.
24 changes: 24 additions & 0 deletions projects/unirest-java/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# 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.
#
##########################################################################
FROM gcr.io/oss-fuzz-base/base-builder-jvm
RUN curl -L https://archive.apache.org/dist/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.zip \
-o maven.zip && \
unzip maven.zip -d $SRC/maven && \
rm maven.zip
ENV MVN $SRC/maven/apache-maven-3.6.3/bin/mvn
RUN git clone --depth 1 https://github.com/Mashape/unirest-java unirest-java
COPY *.sh *.java $SRC/
WORKDIR $SRC/unirest-java
35 changes: 35 additions & 0 deletions projects/unirest-java/JacksonEngineFuzzer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// 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.
//
///////////////////////////////////////////////////////////////////////////
import com.code_intelligence.jazzer.api.FuzzedDataProvider;
import kong.unirest.core.json.JsonEngine;
import kong.unirest.core.json.JSONException;
import kong.unirest.jackson.JacksonEngine;

// Generated with https://github.com/ossf/fuzz-introspector/tree/main/tools/auto-fuzz
// Minor modifications to beautify code and ensure exception is caught.
// jvm-autofuzz-heuristics-2
// Heuristic name: jvm-autofuzz-heuristics-2
// Target method: [kong.unirest.jackson.JacksonEngine] public kong.unirest.core.json.JsonEngine$Object newEngineObject(java.lang.String) throws kong.unirest.core.json.JSONExce>
public class JacksonEngineFuzzer {
public static void fuzzerTestOneInput(FuzzedDataProvider data) {
try {
JacksonEngine obj = new JacksonEngine();
obj.newEngineObject(data.consumeRemainingAsString());
} catch (JSONException e1) {
// Known exception
}
}
}
35 changes: 35 additions & 0 deletions projects/unirest-java/JsonArrayFuzzer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// 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.
//
///////////////////////////////////////////////////////////////////////////
import com.code_intelligence.jazzer.api.FuzzedDataProvider;
import kong.unirest.core.json.JSONArray;
import kong.unirest.core.json.JSONException;
import kong.unirest.core.json.JSONObject;

// Generated with https://github.com/ossf/fuzz-introspector/tree/main/tools/auto-fuzz
// Minor modifications to beautify code and ensure exception is caught.
// jvm-autofuzz-heuristics-2
// Heuristic name: jvm-autofuzz-heuristics-2
// Target method: [kong.unirest.core.json.JSONArray] public kong.unirest.core.json.JSONObject toJSONObject(kong.unirest.core.json.JSONArray) throws kong.unirest.core.json.JSON>
public class JsonArrayFuzzer {
public static void fuzzerTestOneInput(FuzzedDataProvider data) {
try {
JSONArray obj = new JSONArray(data.consumeRemainingAsString());
obj.toJSONObject(new JSONArray());
} catch (JSONException e1) {
//Known exception
}
}
}
64 changes: 64 additions & 0 deletions projects/unirest-java/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/bin/bash -eu
# 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.
#
##########################################################################
$MVN clean package -Dmaven.javadoc.skip=true -DskipTests=true -Dpmd.skip=true \
-Dencoding=UTF-8 -Dmaven.antrun.skip=true -Dcheckstyle.skip=true \
-Denforcer.fail=false org.apache.maven.plugins:maven-shade-plugin:3.2.4:shade
CURRENT_VERSION=$($MVN org.apache.maven.plugins:maven-help-plugin:3.2.0:evaluate \
-Dexpression=project.version -q -DforceStdout)

cp "object-mapper-jackson/target/unirest-objectmapper-jackson-$CURRENT_VERSION.jar" $OUT/jackson.jar
cp "object-mapper-gson/target/unirest-object-mappers-gson-$CURRENT_VERSION.jar" $OUT/gson.jar
cp "unirest/target/unirest-java-core-$CURRENT_VERSION.jar" $OUT/unirest.jar

ALL_JARS="jackson.jar gson.jar unirest.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/bash
# LLVMFuzzerTestOneInput for fuzzer detection.
this_dir=\$(dirname "\$0")
if [[ "\$@" =~ (^| )-runs=[0-9]+($| ) ]]
then
mem_settings='-Xmx1900m:-Xss900k'
else
mem_settings='-Xmx2048m:-Xss1024k'
fi
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="\$mem_settings" \
\$@" > $OUT/$fuzzer_basename

chmod u+x $OUT/$fuzzer_basename
done

11 changes: 11 additions & 0 deletions projects/unirest-java/project.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
homepage: https://github.com/Mashape/unirest-java
main_repo: https://github.com/Mashape/unirest-java
language: jvm
fuzzing_engines:
- libfuzzer
sanitizers:
- address
vendor_ccs:
- [email protected]
- [email protected]
- [email protected]

0 comments on commit 868a94f

Please sign in to comment.