...

Source file src/github.com/redis/go-redis/v9/fuzz/fuzz.go

Documentation: github.com/redis/go-redis/v9/fuzz

     1  //go:build gofuzz
     2  // +build gofuzz
     3  
     4  package fuzz
     5  
     6  import (
     7  	"context"
     8  	"time"
     9  
    10  	"github.com/redis/go-redis/v9"
    11  )
    12  
    13  var (
    14  	ctx = context.Background()
    15  	rdb *redis.Client
    16  )
    17  
    18  func init() {
    19  	rdb = redis.NewClient(&redis.Options{
    20  		Addr:         ":6379",
    21  		DialTimeout:  10 * time.Second,
    22  		ReadTimeout:  10 * time.Second,
    23  		WriteTimeout: 10 * time.Second,
    24  		PoolSize:     10,
    25  		PoolTimeout:  10 * time.Second,
    26  	})
    27  }
    28  
    29  func Fuzz(data []byte) int {
    30  	arrayLen := len(data)
    31  	if arrayLen < 4 {
    32  		return -1
    33  	}
    34  	maxIter := int(uint(data[0]))
    35  	for i := 0; i < maxIter && i < arrayLen; i++ {
    36  		n := i % arrayLen
    37  		if n == 0 {
    38  			_ = rdb.Set(ctx, string(data[i:]), string(data[i:]), 0).Err()
    39  		} else if n == 1 {
    40  			_, _ = rdb.Get(ctx, string(data[i:])).Result()
    41  		} else if n == 2 {
    42  			_, _ = rdb.Incr(ctx, string(data[i:])).Result()
    43  		} else if n == 3 {
    44  			var cursor uint64
    45  			_, _, _ = rdb.Scan(ctx, cursor, string(data[i:]), 10).Result()
    46  		}
    47  	}
    48  	return 1
    49  }
    50  

View as plain text