fuzzing

package module
v0.0.0-...-53bd556 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2020 License: Apache-2.0 Imports: 5 Imported by: 0

README

fuzzing

codecov GoDoc

Package fuzzing enables easy fuzzing with go-fuzz.

The Fuzz object provides functions for generating consistent Go primitive values from a given fuzzed bytes slice. The generated values are promised to be consistent from identical slices. They are also correlated to the given fuzzed slice to enable fuzzing exploration.

For an example on how to use this library with go-fuzz, see ./example_fuzz.go In order to test the example, run in the project directory:

$ go get -u github.com/dvyukov/go-fuzz/go-fuzz github.com/dvyukov/go-fuzz/go-fuzz-build
$ go-fuzz-build
$ go-fuzz -testoutput

Examples

f := New([]byte{1, 2, 3})
i := f.Int()
fmt.Println(i)

Output:

3851489450890114710

Readme created from Go doc with goreadme

Documentation

Overview

Package fuzzing enables easy fuzzing with (go-fuzz) https://github.com/dvyukov/go-fuzz.

The `Fuzz` object provides functions for generating consistent Go primitive values from a given fuzzed bytes slice. The generated values are promised to be consistent from identical slices. They are also correlated to the given fuzzed slice to enable fuzzing exploration.

For an example on how to use this library with go-fuzz, see ./example_fuzz.go In order to test the example, run in the project directory:

$ go get -u github.com/dvyukov/go-fuzz/go-fuzz github.com/dvyukov/go-fuzz/go-fuzz-build
$ go-fuzz-build
$ go-fuzz -testoutput
Example
f := New([]byte{1, 2, 3})
i := f.Int()
fmt.Println(i)
Output:

3851489450890114710

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Fuzz

type Fuzz struct {
	// contains filtered or unexported fields
}

Fuzz is a fuzzing helper object. It provides functions for generating consistent Go primitive values from a given fuzzed bytes slice. The generated values are promised to be consistent from a identical slices. They are also correlated to the given fuzzed slice to enable fuzzing exploration.

func New

func New(data []byte) *Fuzz

New returns a Fuzz (see Fuzz definition).

This function consumes that first 8 bytes and convert them to a uint64 for a random seed for pseudo random generator, the rest of the data is consumed as input to generate the fuzzed objects. When all the data is consumed, the created pseudo random generator is used to generate the fuzzed objects.

func (*Fuzz) Bool

func (f *Fuzz) Bool() bool

Bool consumes one byte and converts it to a boolean value.

func (*Fuzz) Bytes

func (f *Fuzz) Bytes(n int) []byte

Bytes consumes n bytes and returns them.

func (*Fuzz) Int

func (f *Fuzz) Int() int

Int consumes 8 bytes and return their conversion to int.

func (*Fuzz) Int31

func (f *Fuzz) Int31() int32

Int31 consumes 4 bytes and return their conversion to int32 in the range [0, 1<<31).

func (*Fuzz) Int32

func (f *Fuzz) Int32() int32

Int32 consumes 4 bytes and return their conversion to int32.

func (*Fuzz) Int63

func (f *Fuzz) Int63() int64

Int63 consumes 8 bytes and return their conversion to int64 in the range [0, 1<<63).

func (*Fuzz) Int64

func (f *Fuzz) Int64() int64

Int64 consumes 8 bytes and return their conversion to int64.

func (*Fuzz) Read

func (f *Fuzz) Read(b []byte) (int, error)

Read reads from source. If the source was exhausted, it reads from the random fallback. The returned error should always be nil.

func (*Fuzz) ReadRune

func (f *Fuzz) ReadRune() (r rune, size int, err error)

ReadRune consumes a single rune. The returned error should always be nil.

func (*Fuzz) Rune

func (f *Fuzz) Rune() rune

Rune is a convenience method around ReadRune.

func (*Fuzz) String

func (f *Fuzz) String(n int) string

String consumes n runes and return them as a string.

func (*Fuzz) Uint

func (f *Fuzz) Uint() uint

Uint consumes 8 bytes and return their conversion to uint.

func (*Fuzz) Uint32

func (f *Fuzz) Uint32() uint32

Uint32 consumes 4 bytes and return their conversion to uint32.

func (*Fuzz) Uint64

func (f *Fuzz) Uint64() uint64

Uint64 consumes 8 bytes and return their conversion to uint64.

Jump to

Keyboard shortcuts

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