Skip to content

Rejecting unwanted inputs?Β #214

@msyrota

Description

@msyrota

I use repeated messages in my fuzzing harness and length 0 (which it can supply) is unfortunately invalid for me. In a "classic" libFuzzer harness, whenever I get invalid input, I can reject it by returning -1, however for some reason libprotobuf-mutator ignores TestOneInput return code and I get invalid protobufs in my corpus. I've tried the following to propagate the return code, but to no avail:

diff --git a/src/libfuzzer/libfuzzer_macro.h b/src/libfuzzer/libfuzzer_macro.h
index b5cb201..70c3ff4 100644
--- a/src/libfuzzer/libfuzzer_macro.h
+++ b/src/libfuzzer/libfuzzer_macro.h
@@ -74,8 +74,8 @@
     using protobuf_mutator::libfuzzer::LoadProtoInput;                      \
     Proto input;                                                            \
     if (LoadProtoInput(use_binary, data, size, &input))                     \
-      TestOneProtoInput(input);                                             \
-    return 0;                                                               \
+      return TestOneProtoInput(input);                                      \
+    return -1;                                                              \
   }
 
 #define DEFINE_POST_PROCESS_PROTO_MUTATION_IMPL(Proto) \
@@ -83,7 +83,7 @@
       protobuf_mutator::libfuzzer::PostProcessorRegistration<Proto>;
 
 #define DEFINE_PROTO_FUZZER_IMPL(use_binary, arg)                 \
-  static void TestOneProtoInput(arg);                             \
+  static int TestOneProtoInput(arg);                              \
   using FuzzerProtoType =                                         \
       protobuf_mutator::libfuzzer::macro_internal::GetFirstParam< \
           decltype(&TestOneProtoInput)>::type;                    \
@@ -91,7 +91,7 @@
   DEFINE_CUSTOM_PROTO_CROSSOVER_IMPL(use_binary, FuzzerProtoType) \
   DEFINE_TEST_ONE_PROTO_INPUT_IMPL(use_binary, FuzzerProtoType)   \
   DEFINE_POST_PROCESS_PROTO_MUTATION_IMPL(FuzzerProtoType)        \
-  static void TestOneProtoInput(arg)
+  static int TestOneProtoInput(arg)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions