goprotofuzz

package module
v0.0.0-...-8d0e21b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 6, 2022 License: MIT Imports: 8 Imported by: 0

README

goprotofuzz

goprotofuzz is a protoc plugin used to generate fuzzing functions suitable for use with gofuzz.

Usage

Install the plugin,

go install github.com/srikrsna/goprotofuzz/cmd/protoc-gen-gofuzz@latest

For a protobuf definition like this,

syntax = "proto3";

package pb;

option go_package = "github.com/srikrsna/goprotofuzz/example;pb";

message SomeMessage {
  string string_field = 1;
  int32 int32_field = 2;
  bool bool_field = 3;
  InnerMessage inner_message = 4;
  oneof some_oneof {
    string oneof_string = 5;
    bool oneof_bool = 6;
  }
  repeated string slice_string = 7;
  repeated InnerMessage slice_message = 8;
}

message InnerMessage { string inner_field = 1; }

Fuzz functions can be generated using

protoc -I . --fuzz_out=:. example/example.proto

and can be used in testing as follow,

go get github.com/srikrsna/goprotofuzz

package pb_test

import (
	"testing"

	fuzz "github.com/google/gofuzz"
	pb "github.com/srikrsna/goprotofuzz/example"
	pbfuzz "github.com/srikrsna/goprotofuzz/examplefuzz"
)

func TestFuzz(t *testing.T) {
	fz := fuzz.New().Funcs(pbfuzz.FuzzFuncs()...)

	var msg pb.SomeMessage
	fz.Fuzz(&msg)

	// Test using random msg
}

Documentation

Index

Constants

This section is empty.

Variables

Functions

func FuzzAny

func FuzzAny(msg *anypb.Any, c fuzz.Continue)

FuzzAny can be used to Fuzz google.protobuf.Any messages. It fills a fuzzed google.protobuf.Struct message.

func FuzzDuration

func FuzzDuration(msg *durationpb.Duration, c fuzz.Continue)

FuzzDuration can be used to Fuzz google.protobuf.Duration messages. It's range is [0, 1 year)

func FuzzFieldMask

func FuzzFieldMask(msg *fieldmaskpb.FieldMask, c fuzz.Continue)

FuzzFieldMask can be used to Fuzz google.protobuf.FieldMask messages. They produce valid lower_snake_case paths

func FuzzStruct

func FuzzStruct(msg *structpb.Struct, c fuzz.Continue)

FuzzStruct can be used to Fuzz google.protobuf.Struct messages. # of fields will be in [0, 64). Each field will be one of float, bool, or string

func FuzzTimestamp

func FuzzTimestamp(msg *timestamppb.Timestamp, c fuzz.Continue)

FuzzTimestamp can be used to Fuzz google.protobuf.Timestamp messages. It's range is same as default time.Time fuzzer of gofuzz

Types

This section is empty.

Directories

Path Synopsis
cmd
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL