mirror of https://github.com/google/oss-fuzz.git
Initial integration (#7678)
This commit is contained in:
parent
61c1a70e26
commit
c67838b2f5
|
@ -0,0 +1,104 @@
|
|||
import com.code_intelligence.jazzer.api.FuzzedDataProvider;
|
||||
|
||||
import org.apache.hc.core5.http.Method;
|
||||
import org.apache.hc.core5.http.message.BasicClassicHttpRequest;
|
||||
import org.apache.hc.core5.http.io.entity.*;
|
||||
import org.apache.hc.core5.http.ContentType;
|
||||
import org.apache.hc.core5.http.impl.bootstrap.RequesterBootstrap;
|
||||
import org.apache.hc.core5.http.protocol.HttpCoreContext;
|
||||
import org.apache.hc.core5.http.HttpHost;
|
||||
import org.apache.hc.core5.http.impl.bootstrap.HttpRequester;
|
||||
import org.apache.hc.core5.util.Timeout;
|
||||
import org.apache.hc.core5.http.HttpException;
|
||||
import org.apache.hc.core5.http.HttpVersion;
|
||||
import org.apache.hc.core5.http.message.BasicHeader;
|
||||
import org.apache.hc.core5.net.URIAuthority;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.lang.IllegalArgumentException;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.ByteArrayInputStream;
|
||||
|
||||
public class ClassicHttpRequestFuzzer {
|
||||
final static ContentType[] contentTypes = {
|
||||
ContentType.APPLICATION_ATOM_XML,
|
||||
ContentType.APPLICATION_FORM_URLENCODED,
|
||||
ContentType.APPLICATION_JSON,
|
||||
ContentType.APPLICATION_SVG_XML,
|
||||
ContentType.APPLICATION_XHTML_XML,
|
||||
ContentType.APPLICATION_XML,
|
||||
ContentType.IMAGE_BMP,
|
||||
ContentType.IMAGE_GIF,
|
||||
ContentType.IMAGE_JPEG,
|
||||
ContentType.IMAGE_PNG,
|
||||
ContentType.IMAGE_SVG,
|
||||
ContentType.IMAGE_TIFF,
|
||||
ContentType.IMAGE_WEBP,
|
||||
ContentType.MULTIPART_FORM_DATA,
|
||||
ContentType.TEXT_HTML,
|
||||
ContentType.TEXT_PLAIN,
|
||||
ContentType.TEXT_XML
|
||||
};
|
||||
|
||||
public static void fuzzerTestOneInput(FuzzedDataProvider data) {
|
||||
int entityChoice = data.consumeInt(0, 3);
|
||||
String name = data.consumeString(100);
|
||||
String value = data.consumeRemainingAsString();
|
||||
BasicClassicHttpRequest request;
|
||||
|
||||
try {
|
||||
request = new BasicClassicHttpRequest(data.pickValue(Method.values()), value);
|
||||
} catch (IllegalArgumentException e) {
|
||||
return;
|
||||
}
|
||||
|
||||
request.setVersion(data.pickValue(HttpVersion.ALL));
|
||||
request.addHeader(value, new Object());
|
||||
request.addHeader(new BasicHeader(name, value));
|
||||
request.setScheme(value);
|
||||
request.setAuthority(new URIAuthority(value, 8080));
|
||||
setRequestEntity(request, value, entityChoice, data.pickValue(contentTypes));
|
||||
|
||||
request.getRequestUri();
|
||||
request.getPath();
|
||||
request.toString();
|
||||
request.getScheme();
|
||||
request.getEntity();
|
||||
request.getAuthority();
|
||||
try {
|
||||
request.getUri();
|
||||
} catch (URISyntaxException e) { }
|
||||
|
||||
HttpRequester requester = RequesterBootstrap.bootstrap()
|
||||
.setSslContext(null)
|
||||
.setMaxTotal(2)
|
||||
.setDefaultMaxPerRoute(2)
|
||||
.create();
|
||||
|
||||
final HttpHost target = new HttpHost(value, "localhost", 80);
|
||||
final HttpCoreContext context = HttpCoreContext.create();
|
||||
try {
|
||||
requester.execute(target, request, Timeout.ofSeconds(0), context);
|
||||
} catch (HttpException | IOException e) { }
|
||||
}
|
||||
|
||||
public static void setRequestEntity(BasicClassicHttpRequest request, String value, int entityChoice, ContentType contentType) {
|
||||
ByteArrayInputStream stream = new ByteArrayInputStream(value.getBytes());
|
||||
switch (entityChoice) {
|
||||
case 0:
|
||||
request.setEntity(new StringEntity(value, contentType));
|
||||
break;
|
||||
case 1:
|
||||
request.setEntity(new InputStreamEntity(stream,contentType));
|
||||
break;
|
||||
case 2:
|
||||
request.setEntity(new BasicHttpEntity(stream, contentType));
|
||||
break;
|
||||
case 3:
|
||||
request.setEntity(new ByteArrayEntity(value.getBytes(), contentType));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
# 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/apache/httpcomponents-core -b 5.1.x
|
||||
|
||||
ENV MVN $SRC/maven/apache-maven-3.6.3/bin/mvn
|
||||
|
||||
COPY build.sh $SRC/
|
||||
COPY *Fuzzer.java $SRC/
|
||||
WORKDIR httpcomponents-core
|
|
@ -0,0 +1,51 @@
|
|||
#!/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.
|
||||
#
|
||||
################################################################################
|
||||
|
||||
MAVEN_ARGS="-Djavac.src.version=15 -Djavac.target.version=15 -DskipTests"
|
||||
$MVN package $MAVEN_ARGS
|
||||
|
||||
$MVN package $MAVEN_ARGS
|
||||
CURRENT_VERSION=$($MVN org.apache.maven.plugins:maven-help-plugin:3.2.0:evaluate \
|
||||
-Dexpression=project.version -q -DforceStdout)
|
||||
cp "httpcore5/target/httpcore5-$CURRENT_VERSION.jar" "$OUT/httpcore5.jar"
|
||||
|
||||
ALL_JARS="httpcore5.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
|
|
@ -0,0 +1,13 @@
|
|||
homepage: "https://github.com/apache/httpcomponents-core"
|
||||
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
|
||||
main_repo: "https://github.com/apache/httpcomponents-core.git"
|
||||
sanitizers:
|
||||
- address
|
Loading…
Reference in New Issue