-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
228 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/main/java/com/code_intelligence/jazzer/mutation/annotation/proto/DescriptorSource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright 2023 Code Intelligence GmbH | ||
* | ||
* 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 com.code_intelligence.jazzer.mutation.annotation.proto; | ||
|
||
import static java.lang.annotation.ElementType.TYPE_USE; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
import com.code_intelligence.jazzer.mutation.annotation.AppliesTo; | ||
import com.google.protobuf.DynamicMessage; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* Provides a {@link com.google.protobuf.Descriptors.Descriptor} to use as the base for mutations | ||
* of the annotated {@link DynamicMessage} or {@link DynamicMessage.Builder}. | ||
*/ | ||
@Target(TYPE_USE) | ||
@Retention(RUNTIME) | ||
@AppliesTo({DynamicMessage.class, DynamicMessage.Builder.class}) | ||
public @interface DescriptorSource { | ||
/** | ||
* The fully qualified name of a static final field (e.g. {@code com.example.MyClass#MY_FIELD} of | ||
* type * {@link com.google.protobuf.Descriptors.Descriptor} that mutations should be based on. | ||
*/ | ||
String value(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
tests/src/test/java/com/example/ExperimentalMutatorDynamicProtoFuzzer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright 2023 Code Intelligence GmbH | ||
* | ||
* 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 com.example; | ||
|
||
import com.code_intelligence.jazzer.api.FuzzerSecurityIssueMedium; | ||
import com.code_intelligence.jazzer.mutation.annotation.NotNull; | ||
import com.code_intelligence.jazzer.mutation.annotation.proto.DescriptorSource; | ||
import com.google.protobuf.DescriptorProtos.DescriptorProto; | ||
import com.google.protobuf.DescriptorProtos.FieldDescriptorProto; | ||
import com.google.protobuf.DescriptorProtos.FieldDescriptorProto.Type; | ||
import com.google.protobuf.DescriptorProtos.FileDescriptorProto; | ||
import com.google.protobuf.Descriptors.Descriptor; | ||
import com.google.protobuf.Descriptors.DescriptorValidationException; | ||
import com.google.protobuf.Descriptors.FieldDescriptor; | ||
import com.google.protobuf.Descriptors.FileDescriptor; | ||
import com.google.protobuf.DynamicMessage; | ||
|
||
public class ExperimentalMutatorDynamicProtoFuzzer { | ||
private static final Descriptor DESCRIPTOR = makeDescriptor(); | ||
private static final FieldDescriptor I32 = DESCRIPTOR.findFieldByName("i32"); | ||
private static final FieldDescriptor STR = DESCRIPTOR.findFieldByName("str"); | ||
|
||
public static void fuzzerTestOneInput(@NotNull @DescriptorSource( | ||
"com.example.ExperimentalMutatorDynamicProtoFuzzer#DESCRIPTOR") DynamicMessage proto) { | ||
if (proto.getField(I32).equals(1234) && proto.getField(STR).equals("abcd")) { | ||
throw new FuzzerSecurityIssueMedium("Secret proto is found!"); | ||
} | ||
} | ||
|
||
private static Descriptor makeDescriptor() { | ||
DescriptorProto myMessage = | ||
DescriptorProto.newBuilder() | ||
.setName("my_message") | ||
.addField(FieldDescriptorProto.newBuilder().setNumber(1).setName("i32").setType( | ||
Type.TYPE_INT32)) | ||
.addField(FieldDescriptorProto.newBuilder().setNumber(2).setName("str").setType( | ||
Type.TYPE_STRING)) | ||
.build(); | ||
FileDescriptorProto file = FileDescriptorProto.newBuilder() | ||
.setName("my_protos.proto") | ||
.addMessageType(myMessage) | ||
.build(); | ||
try { | ||
return FileDescriptor.buildFrom(file, new FileDescriptor[0]) | ||
.findMessageTypeByName("my_message"); | ||
} catch (DescriptorValidationException e) { | ||
throw new IllegalStateException(e); | ||
} | ||
} | ||
} |