From cfd9136d32cb39169a3a92ed1a87eef8d1f522b6 Mon Sep 17 00:00:00 2001 From: Cedric Champeau Date: Mon, 6 Jan 2025 17:27:24 +0100 Subject: [PATCH 1/3] Publish jazzer plugin This commit adds publishing of the Jazzer plugin. It will NOT be published on the Gradle plugin portal, but on Maven Central only. This shouldn't be an issue, except that users won't be able to find it when searching on the plugin portal (similarly to the native build tools). It may be worth checking before a 1.0.0 release with a beta version or something, since the setup is a bit special. Fixes #100 --- build.gradle | 13 +++++++++++++ fuzzing-tests/gradle.properties | 1 + gradle.properties | 2 -- jazzer-plugin/build.gradle.kts | 1 + jazzer-plugin/gradle.properties | 1 + jazzer-plugin/settings.gradle.kts | 4 ++-- settings.gradle.kts | 6 ++++-- 7 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 fuzzing-tests/gradle.properties create mode 100644 jazzer-plugin/gradle.properties diff --git a/build.gradle b/build.gradle index 5cdc7d1..2f92fda 100644 --- a/build.gradle +++ b/build.gradle @@ -2,3 +2,16 @@ plugins { id "io.micronaut.build.internal.docs" id "io.micronaut.build.internal.quality-reporting" } + +// These tasks are used in the release workflow, but the jazzer plugin is an included build +["publishAllPublicationsToBuildRepository", "publishToSonatype", "closeAndReleaseSonatypeStagingRepository"].each {t -> + if (tasks.names.find { it == t } == null) { + tasks.register(t) { + dependsOn(gradle.includedBuilds.find { it.name == "micronaut-jazzer-plugin" }.task(":$t")) + } + } else { + tasks.named(t) { + dependsOn(gradle.includedBuilds.find { it.name == "micronaut-jazzer-plugin" }.task(":$t")) + } + } +} diff --git a/fuzzing-tests/gradle.properties b/fuzzing-tests/gradle.properties new file mode 100644 index 0000000..5158245 --- /dev/null +++ b/fuzzing-tests/gradle.properties @@ -0,0 +1 @@ +micronautPublish=false diff --git a/gradle.properties b/gradle.properties index 1d18bba..21a0824 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,8 +1,6 @@ projectVersion=1.0.0-SNAPSHOT projectGroup=io.micronaut.fuzzing -micronautPublish=false - title=Micronaut fuzzing projectDesc=TODO projectUrl=https://micronaut.io diff --git a/jazzer-plugin/build.gradle.kts b/jazzer-plugin/build.gradle.kts index 4e01f37..7ba41fd 100644 --- a/jazzer-plugin/build.gradle.kts +++ b/jazzer-plugin/build.gradle.kts @@ -1,5 +1,6 @@ plugins { id("java-gradle-plugin") + id("io.micronaut.build.internal.publishing") } repositories { diff --git a/jazzer-plugin/gradle.properties b/jazzer-plugin/gradle.properties new file mode 100644 index 0000000..af041f8 --- /dev/null +++ b/jazzer-plugin/gradle.properties @@ -0,0 +1 @@ +projectDesc=A Gradle plugin integrating with Jazzer diff --git a/jazzer-plugin/settings.gradle.kts b/jazzer-plugin/settings.gradle.kts index a8c1a3f..217521f 100644 --- a/jazzer-plugin/settings.gradle.kts +++ b/jazzer-plugin/settings.gradle.kts @@ -1,7 +1,7 @@ -rootProject.name = "jazzer-plugin" +rootProject.name = "micronaut-jazzer-plugin" plugins { - id("io.micronaut.build.shared.settings") version "7.3.0" + id("io.micronaut.build.shared.settings") version "7.3.1" } enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") diff --git a/settings.gradle.kts b/settings.gradle.kts index f774dd6..3d0da2e 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -3,11 +3,13 @@ pluginManagement { gradlePluginPortal() mavenCentral() } - includeBuild("jazzer-plugin") + includeBuild("jazzer-plugin") { + name = "micronaut-jazzer-plugin" + } } plugins { - id("io.micronaut.build.shared.settings") version "7.3.0" + id("io.micronaut.build.shared.settings") version "7.3.1" } rootProject.name = "fuzzing-parent" From 2db2c2a0a55825708f8b2236243e51772c5fd76d Mon Sep 17 00:00:00 2001 From: Cedric Champeau Date: Mon, 6 Jan 2025 17:41:36 +0100 Subject: [PATCH 2/3] Make spotless happy --- ...micronaut.build.internal.fuzzing-module.gradle | 6 ++++++ .../fuzzing/processor/DefinedFuzzTarget.java | 15 +++++++++++++++ .../fuzzing/processor/FuzzTargetVisitor.java | 15 +++++++++++++++ .../src/main/java/io/micronaut/fuzzing/Dict.java | 15 +++++++++++++++ .../java/io/micronaut/fuzzing/DictResource.java | 15 +++++++++++++++ .../java/io/micronaut/fuzzing/FuzzTarget.java | 15 +++++++++++++++ .../main/java/io/micronaut/fuzzing/HttpDict.java | 15 +++++++++++++++ .../io/micronaut/fuzzing/http/ByteSeparator.java | 15 +++++++++++++++ 8 files changed, 111 insertions(+) diff --git a/buildSrc/src/main/groovy/io.micronaut.build.internal.fuzzing-module.gradle b/buildSrc/src/main/groovy/io.micronaut.build.internal.fuzzing-module.gradle index c642f0e..b9c2f00 100644 --- a/buildSrc/src/main/groovy/io.micronaut.build.internal.fuzzing-module.gradle +++ b/buildSrc/src/main/groovy/io.micronaut.build.internal.fuzzing-module.gradle @@ -2,3 +2,9 @@ plugins { id 'io.micronaut.build.internal.fuzzing-base' id "io.micronaut.build.internal.module" } + +micronautBuild { + binaryCompatibility { + enabledAfter "1.0.0" + } +} diff --git a/fuzzing-annotation-processor/src/main/java/io/micronaut/fuzzing/processor/DefinedFuzzTarget.java b/fuzzing-annotation-processor/src/main/java/io/micronaut/fuzzing/processor/DefinedFuzzTarget.java index 6f347cf..cea5136 100644 --- a/fuzzing-annotation-processor/src/main/java/io/micronaut/fuzzing/processor/DefinedFuzzTarget.java +++ b/fuzzing-annotation-processor/src/main/java/io/micronaut/fuzzing/processor/DefinedFuzzTarget.java @@ -1,3 +1,18 @@ +/* + * Copyright 2017-2025 original authors + * + * 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 + * + * https://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 io.micronaut.fuzzing.processor; import java.util.List; diff --git a/fuzzing-annotation-processor/src/main/java/io/micronaut/fuzzing/processor/FuzzTargetVisitor.java b/fuzzing-annotation-processor/src/main/java/io/micronaut/fuzzing/processor/FuzzTargetVisitor.java index d6f2ff5..3e4c3c4 100644 --- a/fuzzing-annotation-processor/src/main/java/io/micronaut/fuzzing/processor/FuzzTargetVisitor.java +++ b/fuzzing-annotation-processor/src/main/java/io/micronaut/fuzzing/processor/FuzzTargetVisitor.java @@ -1,3 +1,18 @@ +/* + * Copyright 2017-2025 original authors + * + * 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 + * + * https://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 io.micronaut.fuzzing.processor; import com.fasterxml.jackson.databind.ObjectMapper; 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 9fd6b62..2110343 100644 --- a/fuzzing-api/src/main/java/io/micronaut/fuzzing/Dict.java +++ b/fuzzing-api/src/main/java/io/micronaut/fuzzing/Dict.java @@ -1,3 +1,18 @@ +/* + * Copyright 2017-2025 original authors + * + * 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 + * + * https://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 io.micronaut.fuzzing; import java.lang.annotation.ElementType; 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 03521fc..4777ad4 100644 --- a/fuzzing-api/src/main/java/io/micronaut/fuzzing/DictResource.java +++ b/fuzzing-api/src/main/java/io/micronaut/fuzzing/DictResource.java @@ -1,3 +1,18 @@ +/* + * Copyright 2017-2025 original authors + * + * 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 + * + * https://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 io.micronaut.fuzzing; import java.lang.annotation.ElementType; diff --git a/fuzzing-api/src/main/java/io/micronaut/fuzzing/FuzzTarget.java b/fuzzing-api/src/main/java/io/micronaut/fuzzing/FuzzTarget.java index 6779932..451ebf0 100644 --- a/fuzzing-api/src/main/java/io/micronaut/fuzzing/FuzzTarget.java +++ b/fuzzing-api/src/main/java/io/micronaut/fuzzing/FuzzTarget.java @@ -1,3 +1,18 @@ +/* + * Copyright 2017-2025 original authors + * + * 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 + * + * https://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 io.micronaut.fuzzing; import java.lang.annotation.ElementType; 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 62c039e..2c471dc 100644 --- a/fuzzing-api/src/main/java/io/micronaut/fuzzing/HttpDict.java +++ b/fuzzing-api/src/main/java/io/micronaut/fuzzing/HttpDict.java @@ -1,3 +1,18 @@ +/* + * Copyright 2017-2025 original authors + * + * 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 + * + * https://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 io.micronaut.fuzzing; import java.lang.annotation.ElementType; diff --git a/fuzzing-tests/src/main/java/io/micronaut/fuzzing/http/ByteSeparator.java b/fuzzing-tests/src/main/java/io/micronaut/fuzzing/http/ByteSeparator.java index 7f78b8a..bef2a09 100644 --- a/fuzzing-tests/src/main/java/io/micronaut/fuzzing/http/ByteSeparator.java +++ b/fuzzing-tests/src/main/java/io/micronaut/fuzzing/http/ByteSeparator.java @@ -1,3 +1,18 @@ +/* + * Copyright 2017-2025 original authors + * + * 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 + * + * https://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 io.micronaut.fuzzing.http; import io.netty.buffer.ByteBuf; From 74223df39e61cfadce1ae73136589d775513408b Mon Sep 17 00:00:00 2001 From: yawkat Date: Tue, 7 Jan 2025 11:11:29 +0100 Subject: [PATCH 3/3] cleanup --- .../micronaut/fuzzing/http/ByteSeparator.java | 2 +- .../http/CustomResourceLeakDetector.java | 29 ++++++++++--------- .../fuzzing/http/SimpleController.java | 6 +--- 3 files changed, 17 insertions(+), 20 deletions(-) diff --git a/fuzzing-tests/src/main/java/io/micronaut/fuzzing/http/ByteSeparator.java b/fuzzing-tests/src/main/java/io/micronaut/fuzzing/http/ByteSeparator.java index bef2a09..30c94d5 100644 --- a/fuzzing-tests/src/main/java/io/micronaut/fuzzing/http/ByteSeparator.java +++ b/fuzzing-tests/src/main/java/io/micronaut/fuzzing/http/ByteSeparator.java @@ -28,7 +28,7 @@ * This class splits a byte input into multiple chunks in a fuzzer-friendly way, using the * {@link ByteSeparator#SEPARATOR}. Take care to add the separator to the fuzzer dictionary! */ -public class ByteSeparator { +public final class ByteSeparator { static final String SEPARATOR = "SEP"; private static final ByteBuf SEPARATOR_BYTES = Unpooled.copiedBuffer(SEPARATOR, StandardCharsets.UTF_8); diff --git a/fuzzing-tests/src/main/java/io/micronaut/fuzzing/http/CustomResourceLeakDetector.java b/fuzzing-tests/src/main/java/io/micronaut/fuzzing/http/CustomResourceLeakDetector.java index 9881994..4ebcac3 100644 --- a/fuzzing-tests/src/main/java/io/micronaut/fuzzing/http/CustomResourceLeakDetector.java +++ b/fuzzing-tests/src/main/java/io/micronaut/fuzzing/http/CustomResourceLeakDetector.java @@ -40,11 +40,16 @@ final class CustomResourceLeakDetector extends ResourceLeakDetector { } } - private static final List leaks = new CopyOnWriteArrayList<>(); - private static final List> detectors = new CopyOnWriteArrayList<>(); + private static final List LEAKS = new CopyOnWriteArrayList<>(); + private static final List> DETECTORS = new CopyOnWriteArrayList<>(); private static volatile ResourceLeakHint currentHint = new FixedHint(null); + public CustomResourceLeakDetector(Class resourceType, int samplingInterval) { + super(resourceType, samplingInterval); + DETECTORS.add(this); + } + static void register() { ResourceLeakDetector.setLevel(Level.PARANOID); ResourceLeakDetectorFactory.setResourceLeakDetectorFactory(new ResourceLeakDetectorFactory() { @@ -60,11 +65,6 @@ public static void setCurrentInput(byte[] input) { currentHint = new FixedHint(input); } - public CustomResourceLeakDetector(Class resourceType, int samplingInterval) { - super(resourceType, samplingInterval); - detectors.add(this); - } - @Override protected boolean needReport() { return true; @@ -72,13 +72,13 @@ protected boolean needReport() { @Override protected void reportTracedLeak(String resourceType, String records) { - leaks.add(new Leak(resourceType, records)); + LEAKS.add(new Leak(resourceType, records)); super.reportTracedLeak(resourceType, records); } @Override protected void reportUntracedLeak(String resourceType) { - leaks.add(new Leak(resourceType, null)); + LEAKS.add(new Leak(resourceType, null)); super.reportUntracedLeak(resourceType); } @@ -88,9 +88,9 @@ protected Object getInitialHint(String resourceType) { } static void reportLeaks() { - if (!leaks.isEmpty()) { + if (!LEAKS.isEmpty()) { StringBuilder msg = new StringBuilder("Reported leaks! Probably unrelated to this particular run, though.\n"); - for (Leak leak : leaks) { + for (Leak leak : LEAKS) { msg.append(leak.resourceType).append("\n"); msg.append(leak.records).append("\n"); } @@ -101,7 +101,7 @@ static void reportLeaks() { static void reportStillOpen() { Logger logger = LoggerFactory.getLogger(CustomResourceLeakDetector.class); String found = null; - for (ResourceLeakDetector detector : detectors) { + for (ResourceLeakDetector detector : DETECTORS) { Set s = (Set) ALL_LEAKS_FIELD.get(detector); for (Object o : s) { String v = o.toString(); @@ -118,9 +118,10 @@ static void reportStillOpen() { } } - private record Leak(String resourceType, String records) {} + private record Leak(String resourceType, String records) { + } - private static class FixedHint implements ResourceLeakHint { + private static final class FixedHint implements ResourceLeakHint { private final byte[] associatedInput; private FixedHint(byte[] associatedInput) { diff --git a/fuzzing-tests/src/main/java/io/micronaut/fuzzing/http/SimpleController.java b/fuzzing-tests/src/main/java/io/micronaut/fuzzing/http/SimpleController.java index 6159b38..7e328ae 100644 --- a/fuzzing-tests/src/main/java/io/micronaut/fuzzing/http/SimpleController.java +++ b/fuzzing-tests/src/main/java/io/micronaut/fuzzing/http/SimpleController.java @@ -23,14 +23,10 @@ import io.micronaut.http.annotation.Post; import jakarta.inject.Singleton; import org.reactivestreams.Publisher; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; @Singleton @Controller -public class SimpleController { - private static final Logger LOG = LoggerFactory.getLogger(SimpleController.class); - +public final class SimpleController { static final String ECHO_PUBLISHER = "/echo-publisher"; static final String ECHO_ARRAY = "/echo-array"; static final String ECHO_STRING = "/echo-string";