From 124ef8874e3e6d8b8837499d242a809ff929d47b Mon Sep 17 00:00:00 2001 From: yawkat Date: Thu, 9 Jan 2025 09:05:36 +0100 Subject: [PATCH] Add a http2 target --- .../main/java/io/micronaut/fuzzing/Dict.java | 3 ++ .../io/micronaut/fuzzing/DictResource.java | 3 ++ .../java/io/micronaut/fuzzing/HttpDict.java | 2 ++ .../fuzzing/http/EmbeddedHttp2Target.java | 33 +++++++++++++++++++ .../fuzzing/http/EmbeddedHttpTarget.java | 25 +++++++++++--- 5 files changed, 61 insertions(+), 5 deletions(-) create mode 100644 fuzzing-tests/src/main/java/io/micronaut/fuzzing/http/EmbeddedHttp2Target.java diff --git a/fuzzing-api/src/main/java/io/micronaut/fuzzing/Dict.java b/fuzzing-api/src/main/java/io/micronaut/fuzzing/Dict.java index 2110343..4ef94f7 100644 --- a/fuzzing-api/src/main/java/io/micronaut/fuzzing/Dict.java +++ b/fuzzing-api/src/main/java/io/micronaut/fuzzing/Dict.java @@ -16,6 +16,7 @@ package io.micronaut.fuzzing; import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; import java.lang.annotation.Repeatable; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -31,6 +32,7 @@ @Retention(RetentionPolicy.CLASS) @Target(ElementType.TYPE) @Repeatable(Dict.Repeated.class) +@Inherited public @interface Dict { /** * @return The statically defined dictionary entries @@ -39,6 +41,7 @@ @Retention(RetentionPolicy.CLASS) @Target(ElementType.TYPE) + @Inherited @interface Repeated { Dict[] value(); } diff --git a/fuzzing-api/src/main/java/io/micronaut/fuzzing/DictResource.java b/fuzzing-api/src/main/java/io/micronaut/fuzzing/DictResource.java index 4777ad4..2a04d03 100644 --- a/fuzzing-api/src/main/java/io/micronaut/fuzzing/DictResource.java +++ b/fuzzing-api/src/main/java/io/micronaut/fuzzing/DictResource.java @@ -16,6 +16,7 @@ package io.micronaut.fuzzing; import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; import java.lang.annotation.Repeatable; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -29,6 +30,7 @@ @Retention(RetentionPolicy.CLASS) @Target(ElementType.TYPE) @Repeatable(DictResource.Repeated.class) +@Inherited public @interface DictResource { /** * @return The resource path @@ -37,6 +39,7 @@ @Retention(RetentionPolicy.CLASS) @Target(ElementType.TYPE) + @Inherited @interface Repeated { DictResource[] value(); } diff --git a/fuzzing-api/src/main/java/io/micronaut/fuzzing/HttpDict.java b/fuzzing-api/src/main/java/io/micronaut/fuzzing/HttpDict.java index 2c471dc..c97c290 100644 --- a/fuzzing-api/src/main/java/io/micronaut/fuzzing/HttpDict.java +++ b/fuzzing-api/src/main/java/io/micronaut/fuzzing/HttpDict.java @@ -16,6 +16,7 @@ package io.micronaut.fuzzing; import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; @@ -26,5 +27,6 @@ @Retention(RetentionPolicy.CLASS) @Target(ElementType.TYPE) @DictResource("dictionaries/http.dict") +@Inherited public @interface HttpDict { } diff --git a/fuzzing-tests/src/main/java/io/micronaut/fuzzing/http/EmbeddedHttp2Target.java b/fuzzing-tests/src/main/java/io/micronaut/fuzzing/http/EmbeddedHttp2Target.java new file mode 100644 index 0000000..6dc4257 --- /dev/null +++ b/fuzzing-tests/src/main/java/io/micronaut/fuzzing/http/EmbeddedHttp2Target.java @@ -0,0 +1,33 @@ +package io.micronaut.fuzzing.http; + +import io.micronaut.fuzzing.FuzzTarget; +import io.micronaut.fuzzing.runner.LocalJazzerRunner; + +import java.util.Map; + +@FuzzTarget +public class EmbeddedHttp2Target extends EmbeddedHttpTarget { + private static EmbeddedHttp2Target instance; + + EmbeddedHttp2Target(Map cfg) { + super(cfg); + } + + public static void fuzzerInitialize() { + instance = new EmbeddedHttp2Target(Map.of( + "micronaut.server.http-version", "2.0" + )); + } + + public static void fuzzerTestOneInput(byte[] input) { + instance.run(input); + } + + public static void fuzzerTearDown() { + instance.close(); + } + + public static void main(String[] args) { + LocalJazzerRunner.create(EmbeddedHttp2Target.class).fuzz(); + } +} diff --git a/fuzzing-tests/src/main/java/io/micronaut/fuzzing/http/EmbeddedHttpTarget.java b/fuzzing-tests/src/main/java/io/micronaut/fuzzing/http/EmbeddedHttpTarget.java index f1ad766..098b591 100644 --- a/fuzzing-tests/src/main/java/io/micronaut/fuzzing/http/EmbeddedHttpTarget.java +++ b/fuzzing-tests/src/main/java/io/micronaut/fuzzing/http/EmbeddedHttpTarget.java @@ -39,10 +39,12 @@ SimpleController.ECHO_STRING, SimpleController.ECHO_PIECE_JSON, }) -public class EmbeddedHttpTarget { - private static NettyHttpServer nettyHttpServer; +public class EmbeddedHttpTarget implements AutoCloseable { + private static EmbeddedHttpTarget instance; - public static void fuzzerInitialize() { + private final NettyHttpServer nettyHttpServer; + + EmbeddedHttpTarget(Map cfg) { System.setProperty("io.netty.leakDetection.targetRecords", "100"); String vmName = ManagementFactory.getRuntimeMXBean().getName(); @@ -50,12 +52,24 @@ public static void fuzzerInitialize() { LoggerFactory.getLogger(EmbeddedHttpTarget.class).info("Starting embedded HTTP target. VM name is: {}", vmName); CustomResourceLeakDetector.register(); - ApplicationContext ctx = ApplicationContext.run(); + ApplicationContext ctx = ApplicationContext.run(cfg); nettyHttpServer = (NettyHttpServer) ctx.getBean(EmbeddedServer.class); } + public static void fuzzerInitialize() { + instance = new EmbeddedHttpTarget(Map.of()); + } + public static void fuzzerTestOneInput(byte[] input) { + instance.run(input); + } + + public static void fuzzerTearDown() { + instance.close(); + } + + void run(byte[] input) { CustomResourceLeakDetector.setCurrentInput(input); EmbeddedChannel embeddedChannel = nettyHttpServer.buildEmbeddedChannel(false); @@ -84,7 +98,8 @@ public static void fuzzerTestOneInput(byte[] input) { FlagAppender.checkTriggered(); } - public static void fuzzerTearDown() { + @Override + public void close() { //CustomResourceLeakDetector.reportStillOpen(); }