Skip to content

Commit

Permalink
Add a http2 target
Browse files Browse the repository at this point in the history
  • Loading branch information
yawkat committed Jan 9, 2025
1 parent 1c3436d commit 124ef88
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 5 deletions.
3 changes: 3 additions & 0 deletions fuzzing-api/src/main/java/io/micronaut/fuzzing/Dict.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,6 +32,7 @@
@Retention(RetentionPolicy.CLASS)
@Target(ElementType.TYPE)
@Repeatable(Dict.Repeated.class)
@Inherited
public @interface Dict {
/**
* @return The statically defined dictionary entries
Expand All @@ -39,6 +41,7 @@

@Retention(RetentionPolicy.CLASS)
@Target(ElementType.TYPE)
@Inherited
@interface Repeated {
Dict[] value();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,6 +30,7 @@
@Retention(RetentionPolicy.CLASS)
@Target(ElementType.TYPE)
@Repeatable(DictResource.Repeated.class)
@Inherited
public @interface DictResource {
/**
* @return The resource path
Expand All @@ -37,6 +39,7 @@

@Retention(RetentionPolicy.CLASS)
@Target(ElementType.TYPE)
@Inherited
@interface Repeated {
DictResource[] value();
}
Expand Down
2 changes: 2 additions & 0 deletions fuzzing-api/src/main/java/io/micronaut/fuzzing/HttpDict.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,5 +27,6 @@
@Retention(RetentionPolicy.CLASS)
@Target(ElementType.TYPE)
@DictResource("dictionaries/http.dict")
@Inherited
public @interface HttpDict {
}
Original file line number Diff line number Diff line change
@@ -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<String, Object> 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,37 @@
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<String, Object> cfg) {
System.setProperty("io.netty.leakDetection.targetRecords", "100");

String vmName = ManagementFactory.getRuntimeMXBean().getName();
System.setProperty("VM_NAME", vmName);
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);
Expand Down Expand Up @@ -84,7 +98,8 @@ public static void fuzzerTestOneInput(byte[] input) {
FlagAppender.checkTriggered();
}

public static void fuzzerTearDown() {
@Override
public void close() {
//CustomResourceLeakDetector.reportStillOpen();
}

Expand Down

0 comments on commit 124ef88

Please sign in to comment.