mirror of https://github.com/google/oss-fuzz.git
apache-commons-configuration: initial integration (#7847)
* Added fuzz targets for apache-commons-configuration * Make recommended changes * Further requested changes made
This commit is contained in:
parent
8988e2b8d8
commit
4b851f1e22
|
@ -0,0 +1,52 @@
|
|||
# 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
|
||||
|
||||
# Install a working version of Maven
|
||||
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 -f maven.zip
|
||||
|
||||
ENV MVN $SRC/maven/apache-maven-3.6.3/bin/mvn
|
||||
|
||||
# Clone the commons-configuration library source code
|
||||
RUN git clone --depth=1 "https://gitbox.apache.org/repos/asf/commons-configuration.git" commons-configuration
|
||||
|
||||
# Get the dictionaries
|
||||
RUN git clone --depth=1 "https://github.com/google/fuzzing" fuzzing
|
||||
RUN cp fuzzing/dictionaries/xml.dict $SRC/XMLConfigurationLoadFuzzer.dict
|
||||
|
||||
RUN cp fuzzing/dictionaries/yaml.dict $SRC/YAMLConfigurationReadFuzzer.dict
|
||||
RUN cp $SRC/YAMLConfigurationReadFuzzer.dict $SRC/YAMLConfigurationWriteFuzzer.dict
|
||||
|
||||
RUN cp fuzzing/dictionaries/json.dict $SRC/JSONConfigurationReadFuzzer.dict
|
||||
RUN cp $SRC/JSONConfigurationReadFuzzer.dict $SRC/JSONConfigurationWriteFuzzer.dict
|
||||
|
||||
COPY ini.dict $SRC/INIConfigurationReadFuzzer.dict
|
||||
RUN cp $SRC/INIConfigurationReadFuzzer.dict $SRC/INIConfigurationWriteFuzzer.dict
|
||||
|
||||
# Get the corpora
|
||||
RUN git clone --depth=1 "https://github.com/dvyukov/go-fuzz-corpus" corpora
|
||||
RUN zip -q $SRC/XMLConfigurationLoadFuzzer_seed_corpus.zip corpora/xml/corpus/*
|
||||
|
||||
RUN zip -q $SRC/JSONConfigurationReadFuzzer_seed_corpus.zip corpora/json/corpus/*
|
||||
RUN cp $SRC/JSONConfigurationReadFuzzer_seed_corpus.zip $SRC/JSONConfigurationWriteFuzzer_seed_corpus.zip
|
||||
|
||||
# Copy the build script and all the fuzztargets
|
||||
COPY build.sh $SRC/
|
||||
COPY *Fuzzer.java $SRC/
|
||||
WORKDIR $SRC/commons-configuration
|
|
@ -0,0 +1,31 @@
|
|||
import com.code_intelligence.jazzer.api.FuzzedDataProvider;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.commons.configuration2.INIConfiguration;
|
||||
import org.apache.commons.configuration2.ex.ConfigurationException;
|
||||
|
||||
public class INIConfigurationReadFuzzer extends INIConfiguration {
|
||||
public static void fuzzerTestOneInput(FuzzedDataProvider data) {
|
||||
// Create helper objects from fuzzer data
|
||||
final char commentCharacter = data.consumeChar();
|
||||
final char separatorCharacter = data.consumeChar();
|
||||
final byte[] byteArray = data.consumeBytes(Integer.MAX_VALUE);
|
||||
|
||||
// Create needed objects
|
||||
INIConfiguration iniConfig = new INIConfiguration();
|
||||
InputStream inputStream = new ByteArrayInputStream(byteArray);
|
||||
InputStreamReader reader = new InputStreamReader(inputStream);
|
||||
|
||||
try {
|
||||
iniConfig.setSeparatorUsedInInput(Character.toString(separatorCharacter));
|
||||
iniConfig.setCommentLeadingCharsUsedInInput(Character.toString(commentCharacter));
|
||||
iniConfig.read(reader);
|
||||
} catch (IOException | ConfigurationException ignored) {
|
||||
// expected Exceptions get ignored
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
import com.code_intelligence.jazzer.api.FuzzedDataProvider;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.StringWriter;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.commons.configuration2.INIConfiguration;
|
||||
import org.apache.commons.configuration2.ex.ConfigurationException;
|
||||
|
||||
public class INIConfigurationWriteFuzzer extends INIConfiguration {
|
||||
public static void fuzzerTestOneInput(FuzzedDataProvider data) {
|
||||
// Create helper objects from fuzzer data
|
||||
final char commentCharacter = data.consumeChar();
|
||||
final char inputSeparatorCharacter = data.consumeChar();
|
||||
final char outputSeparatorCharacter = data.consumeChar();
|
||||
final byte[] byteArray = data.consumeBytes(Integer.MAX_VALUE);
|
||||
|
||||
// Create the needed objects
|
||||
INIConfiguration iniConfig = new INIConfiguration();
|
||||
InputStream inputStream = new ByteArrayInputStream(byteArray);
|
||||
InputStreamReader reader = new InputStreamReader(inputStream);
|
||||
StringWriter writer = new StringWriter();
|
||||
|
||||
try {
|
||||
iniConfig.setSeparatorUsedInInput(Character.toString(inputSeparatorCharacter));
|
||||
iniConfig.setCommentLeadingCharsUsedInInput(Character.toString(commentCharacter));
|
||||
iniConfig.read(reader);
|
||||
|
||||
iniConfig.setSeparatorUsedInOutput(Character.toString(outputSeparatorCharacter));
|
||||
iniConfig.write(writer);
|
||||
} catch (IOException | ConfigurationException ignored) {
|
||||
// expected Exceptions get ignored
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
import com.code_intelligence.jazzer.api.FuzzedDataProvider;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.ByteArrayInputStream;
|
||||
|
||||
import org.apache.commons.configuration2.JSONConfiguration;
|
||||
import org.apache.commons.configuration2.ex.ConfigurationException;
|
||||
|
||||
public class JSONConfigurationReadFuzzer {
|
||||
public static void fuzzerTestOneInput(FuzzedDataProvider data) {
|
||||
// Create helper objects from fuzzer data
|
||||
final boolean useReader = data.consumeBoolean();
|
||||
final byte[] byteArray = data.consumeBytes(Integer.MAX_VALUE);
|
||||
|
||||
// Create needed objects
|
||||
final JSONConfiguration jsonConfig = new JSONConfiguration();
|
||||
final InputStream inputStream = new ByteArrayInputStream(byteArray);
|
||||
final InputStreamReader reader;
|
||||
|
||||
try {
|
||||
if (useReader) {
|
||||
reader = new InputStreamReader(inputStream);
|
||||
jsonConfig.read(reader);
|
||||
} else {
|
||||
jsonConfig.read(inputStream);
|
||||
}
|
||||
|
||||
} catch (ConfigurationException ignored) {
|
||||
// expected Exceptions get ignored
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
import com.code_intelligence.jazzer.api.FuzzedDataProvider;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.StringWriter;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.commons.configuration2.JSONConfiguration;
|
||||
import org.apache.commons.configuration2.ex.ConfigurationException;
|
||||
|
||||
public class JSONConfigurationWriteFuzzer {
|
||||
public static void fuzzerTestOneInput(FuzzedDataProvider data) {
|
||||
// Create helper objects from fuzzer data
|
||||
final boolean useReader = data.consumeBoolean();
|
||||
final byte[] byteArray = data.consumeBytes(Integer.MAX_VALUE);
|
||||
|
||||
// Create needed objects
|
||||
JSONConfiguration jsonConfig = new JSONConfiguration();
|
||||
InputStream inputStream = new ByteArrayInputStream(byteArray);
|
||||
InputStreamReader reader;
|
||||
StringWriter writer = new StringWriter();
|
||||
|
||||
try {
|
||||
if (useReader) {
|
||||
reader = new InputStreamReader(inputStream);
|
||||
jsonConfig.read(reader);
|
||||
} else {
|
||||
jsonConfig.read(inputStream);
|
||||
}
|
||||
jsonConfig.write(writer);
|
||||
} catch (IOException | ConfigurationException ignored) {
|
||||
// expected Exceptions get ignored
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
import com.code_intelligence.jazzer.api.FuzzedDataProvider;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.InputStream;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.commons.configuration2.XMLConfiguration;
|
||||
import org.apache.commons.configuration2.ex.ConfigurationException;
|
||||
import org.apache.commons.configuration2.io.FileHandler;
|
||||
|
||||
public class XMLConfigurationLoadFuzzer {
|
||||
public static void fuzzerTestOneInput(FuzzedDataProvider data) {
|
||||
// Create needed objects
|
||||
final File tempFile;
|
||||
try {
|
||||
tempFile = File.createTempFile("XMLConfiguration", "xml");
|
||||
tempFile.deleteOnExit();
|
||||
} catch (IOException ioe) {
|
||||
// Preparations failed ; exit early
|
||||
return;
|
||||
}
|
||||
final String absoluteFilepath = tempFile.getAbsolutePath();
|
||||
|
||||
try {
|
||||
final FileWriter fileWriter = new FileWriter(tempFile);
|
||||
fileWriter.write(data.consumeRemainingAsString());
|
||||
fileWriter.close();
|
||||
} catch (IOException ioe) {
|
||||
// Preparations failed ; exit early
|
||||
return;
|
||||
}
|
||||
|
||||
final FileHandler fileHandler = new FileHandler(new XMLConfiguration());
|
||||
fileHandler.setPath(absoluteFilepath);
|
||||
|
||||
try {
|
||||
fileHandler.load();
|
||||
} catch (ConfigurationException ignored) {
|
||||
// expected Exceptions get ignored
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
import com.code_intelligence.jazzer.api.FuzzedDataProvider;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.commons.configuration2.YAMLConfiguration;
|
||||
import org.apache.commons.configuration2.ex.ConfigurationException;
|
||||
|
||||
public class YAMLConfigurationReadFuzzer {
|
||||
public static void fuzzerTestOneInput(byte[] data) {
|
||||
// Create needed objects
|
||||
YAMLConfiguration yamlConfig = new YAMLConfiguration();
|
||||
InputStream inputStream = new ByteArrayInputStream(data);
|
||||
|
||||
try {
|
||||
yamlConfig.read(inputStream);
|
||||
} catch (ConfigurationException ignored) {
|
||||
// expected Exceptions get ignored
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
import com.code_intelligence.jazzer.api.FuzzedDataProvider;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.StringWriter;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.commons.configuration2.YAMLConfiguration;
|
||||
import org.apache.commons.configuration2.ex.ConfigurationException;
|
||||
|
||||
public class YAMLConfigurationWriteFuzzer {
|
||||
public static void fuzzerTestOneInput(byte[] data) {
|
||||
// Create needed objects
|
||||
YAMLConfiguration yamlConfig = new YAMLConfiguration();
|
||||
InputStream inputStream = new ByteArrayInputStream(data);
|
||||
StringWriter writer = new StringWriter();
|
||||
|
||||
try {
|
||||
yamlConfig.read(inputStream);
|
||||
yamlConfig.write(writer);
|
||||
} catch (IOException | ConfigurationException ignored) {
|
||||
// expected Exceptions get ignored
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
#!/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.
|
||||
#
|
||||
################################################################################
|
||||
|
||||
# Moving the corpora and dictionaries to $OUT
|
||||
mv $SRC/{*.zip,*.dict} $OUT
|
||||
|
||||
# Building the library
|
||||
MAVEN_ARGS="--no-transfer-progress -Dmaven.test.skip=true -Djavac.src.version=15 -Djavac.target.version=15 -Djdk.version=15"
|
||||
|
||||
CURRENT_VERSION=$($MVN org.apache.maven.plugins:maven-help-plugin:3.2.0:evaluate \
|
||||
-Dexpression=project.version -q -DforceStdout)
|
||||
|
||||
## maven-shade-plugin is for packaging all the dependencies into one .jar
|
||||
$MVN clean package org.apache.maven.plugins:maven-shade-plugin:3.2.4:shade $MAVEN_ARGS
|
||||
cp "target/commons-configuration2-$CURRENT_VERSION.jar" "$OUT/commons-configuration.jar"
|
||||
|
||||
ALL_JARS="commons-configuration.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 -iname '*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:-Djava.awt.headless=true\" \
|
||||
\$@" > $OUT/$fuzzer_basename
|
||||
|
||||
# Make the execution wrapper executable
|
||||
chmod +x $OUT/$fuzzer_basename
|
||||
done
|
|
@ -0,0 +1,32 @@
|
|||
# sources:
|
||||
# - https://en.wikipedia.org/wiki/INI_file
|
||||
# - https://docs.microsoft.com/en-us/previous-versions/windows/desktop/ms717987(v=vs.85)
|
||||
|
||||
# Basics
|
||||
assign="="
|
||||
section_left_bracket="["
|
||||
section_right_bracket="]"
|
||||
comment_semicolon=";"
|
||||
comment_hash="#"
|
||||
apostrophe="'"
|
||||
double_quotes="\""
|
||||
|
||||
# Old section nesting symbols
|
||||
backslash="\\"
|
||||
comma=","
|
||||
period="."
|
||||
|
||||
# Escape sequences
|
||||
escaped_backslash="\\'"
|
||||
escaped_double_quotes="\\""
|
||||
escaped_null_byte="\\0"
|
||||
escaped_alert="\\a"
|
||||
escaped_backspace="\\b"
|
||||
escaped_tab="\\t"
|
||||
escaped_carriage_return="\\r"
|
||||
escaped_linefeed="\\n"
|
||||
escaped_semicolon="\\;"
|
||||
escaped_hash="\\#"
|
||||
escaped_equal_sign="\\="
|
||||
escaped_colon="\\:"
|
||||
escaped_unicode_beginning="\\x"
|
|
@ -0,0 +1,13 @@
|
|||
homepage: "https://commons.apache.org/proper/commons-configuration/"
|
||||
language: jvm
|
||||
main_repo: "https://gitbox.apache.org/repos/asf/commons-configuration.git"
|
||||
fuzzing_engines:
|
||||
- libfuzzer
|
||||
sanitizers:
|
||||
- address
|
||||
vendor_ccs:
|
||||
- "wagner@code-intelligence.com"
|
||||
- "yakdan@code-intelligence.com"
|
||||
- "glendowne@code-intelligence.com"
|
||||
- "patrice.salathe@code-intelligence.com"
|
||||
- "yoshi.weber@gmail.com"
|
Loading…
Reference in New Issue