[cglib] Initial Integration (#8429)

This commit is contained in:
aschaich 2022-09-07 16:53:13 +00:00 committed by GitHub
parent a22f581a19
commit 157ce1a9a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 305 additions and 0 deletions

33
projects/cglib/Dockerfile Normal file
View File

@ -0,0 +1,33 @@
# 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
ENV MVN $SRC/maven/apache-maven-3.6.3/bin/mvn
WORKDIR ${SRC}
#
# clone repository
#
RUN git clone https://github.com/cglib/cglib
ADD pom.xml build.sh ${SRC}/
ADD src/ ${SRC}/src/
WORKDIR ${SRC}/cglib

78
projects/cglib/build.sh Normal file
View File

@ -0,0 +1,78 @@
#!/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.
#
################################################################################
#
# cglib uses different variables for the java version.
#
MVN_FLAGS="-Dmaven.compiler.source=15 -Dmaven.compiler.target=15 -DskipTests -Djava.version.source=15 -Djava.version.target=15 -Djavac.target=15"
ALL_JARS=""
# install the build servers' jazzer-api into the maven repository
pushd "/tmp"
${MVN} install:install-file -Dfile=${JAZZER_API_PATH} \
-DgroupId="com.code-intelligence" \
-DartifactId="jazzer-api" \
-Dversion="0.12.0" \
-Dpackaging=jar
popd
pushd "${SRC}/cglib"
${MVN} package ${MVN_FLAGS}
${MVN} install ${MVN_FLAGS}
CURRENT_VERSION=$(${MVN} org.apache.maven.plugins:maven-help-plugin:3.2.0:evaluate \
-Dexpression=project.version -q -DforceStdout)
popd
pushd ${SRC}
${MVN} package -DcglibVersion="${CURRENT_VERSION}" ${MVN_FLAGS}
install -v target/cglib-fuzzer-${CURRENT_VERSION}.jar ${OUT}/cglib-fuzzer-${CURRENT_VERSION}.jar
ALL_JARS="${ALL_JARS} cglib-fuzzer-${CURRENT_VERSION}.jar"
popd
# 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
MVN_FUZZERS_PREFIX="src/main/java"
for fuzzer in $(find ${SRC} -name '*Fuzzer.java'); do
stripped_path=$(echo ${fuzzer} | sed 's|^.*src/main/java/\(.*\).java$|\1|');
# the .java was stripped by sed
if (echo ${stripped_path} | grep ".java$"); then
continue;
fi
fuzzer_basename=$(basename -s .java $fuzzer)
fuzzer_classname=$(echo ${stripped_path} | sed 's|/|.|g');
# 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_classname} \
--jvm_args=\"-Xmx2048m\" \
\$@" > $OUT/${fuzzer_basename}
chmod u+x $OUT/${fuzzer_basename}
done

59
projects/cglib/pom.xml Normal file
View File

@ -0,0 +1,59 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ossfuzz</groupId>
<artifactId>cglib-fuzzer</artifactId>
<version>${cglibVersion}</version>
<packaging>jar</packaging>
<properties>
<maven.compiler.source>15</maven.compiler.source>
<maven.compiler.target>15</maven.compiler.target>
<exec.mainClass>ossfuzz.ASTFuzzer</exec.mainClass>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!--
on the CI, install the jazzer file with
mvn install:install-file -Dfile=${JAZZER_API_PATH} \
-DgroupId="com.code-intelligence" \
-DartifactId="jazzer-api" \
-Dversion="0.12.0" \
-Dpackaging=jar
to avoid mismatching driver/api versions
-->
<dependency>
<groupId>com.code-intelligence</groupId>
<artifactId>jazzer-api</artifactId>
<version>0.12.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/cglib/cglib -->
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>${cglibVersion}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,14 @@
homepage: "https://github.com/cglib/cglib/wiki"
language: jvm
main_repo: "https://github.com/cglib/cglib"
fuzzing_engines:
- libfuzzer
sanitizers:
- address
vendor_ccs:
- "wagner@code-intelligence.com"
- "yakdan@code-intelligence.com"
- "glendowne@code-intelligence.com"
- "patrice.salathe@code-intelligence.com"
- "hlin@code-intelligence.com"
- "schaich@code-intelligence.com"

View File

@ -0,0 +1,121 @@
/*
* 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.
*/
package ossfuzz;
import com.code_intelligence.jazzer.api.FuzzedDataProvider;
import com.code_intelligence.jazzer.api.FuzzerSecurityIssueLow;
import java.lang.reflect.Method;
import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.FixedValue;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;
class SampleClass {
String test() {
return "Hello World";
}
String test(String string) {
return string;
}
};
class FixedValueCallback implements FixedValue {
FixedValueCallback(String string) {
m_string = string;
}
@Override
public Object loadObject() throws Exception {
return m_string;
}
public String getString() {
return m_string;
}
protected String m_string;
}
class MethodInterceptorCallback implements MethodInterceptor {
MethodInterceptorCallback(String string) {
m_string = string;
}
@Override
public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
if (method.getDeclaringClass() == SampleClass.class) {
if (method.getParameterCount() == 0) {
return m_string;
}
}
return proxy.invokeSuper(obj, args);
}
public String getString() {
return m_string;
}
protected String m_string;
}
public class EnhancerFuzzer {
public static void fixedValueCallback(FuzzedDataProvider fuzzedDataProvider) {
Enhancer enhancer = new Enhancer();
enhancer.setSuperclass(SampleClass.class);
FixedValueCallback fixedValueCallback = new FixedValueCallback(fuzzedDataProvider.consumeRemainingAsString());
enhancer.setCallback(fixedValueCallback);
SampleClass proxy = (SampleClass) enhancer.create();
if (!proxy.test().equals(fixedValueCallback.getString())) {
throw new FuzzerSecurityIssueLow("FixedValue defect");
}
if (!proxy.test("someString").equals(fixedValueCallback.getString())) {
throw new FuzzerSecurityIssueLow("FixedValue defect");
}
}
public static void methodInterceptorCallback(FuzzedDataProvider fuzzedDataProvider) {
Enhancer enhancer = new Enhancer();
enhancer.setSuperclass(SampleClass.class);
MethodInterceptorCallback methodInterceptorCallback = new MethodInterceptorCallback(fuzzedDataProvider.consumeString(5));
enhancer.setCallback(methodInterceptorCallback);
SampleClass proxy = (SampleClass) enhancer.create();
if (!proxy.test().equals(methodInterceptorCallback.getString())) {
throw new FuzzerSecurityIssueLow("MethodInterceptor defect");
}
String argument = fuzzedDataProvider.consumeRemainingAsString();
if (!proxy.test(argument).equals(argument)) {
throw new FuzzerSecurityIssueLow("MethodInterceptor defect");
}
}
public static void fuzzerTestOneInput(FuzzedDataProvider fuzzedDataProvider) throws Exception {
fixedValueCallback(fuzzedDataProvider);
methodInterceptorCallback(fuzzedDataProvider);
}
}