2021-09-08 16:00:52 +03:00
|
|
|
//go:build gofuzz
|
2020-11-30 19:26:51 +03:00
|
|
|
// +build gofuzz
|
|
|
|
|
2021-02-04 18:02:17 +03:00
|
|
|
package fuzz
|
2020-11-30 19:02:50 +03:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
2021-09-08 16:00:52 +03:00
|
|
|
|
2022-12-12 15:55:49 +03:00
|
|
|
"git.internal/re/redis/v8"
|
2020-11-30 19:02:50 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
ctx = context.Background()
|
2021-02-06 00:45:09 +03:00
|
|
|
rdb *redis.Client
|
2020-11-30 19:02:50 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2021-02-06 00:45:09 +03:00
|
|
|
rdb = redis.NewClient(&redis.Options{
|
2020-11-30 19:02:50 +03:00
|
|
|
Addr: ":6379",
|
|
|
|
DialTimeout: 10 * time.Second,
|
|
|
|
ReadTimeout: 10 * time.Second,
|
|
|
|
WriteTimeout: 10 * time.Second,
|
|
|
|
PoolSize: 10,
|
|
|
|
PoolTimeout: 10 * time.Second,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func Fuzz(data []byte) int {
|
2020-11-30 19:26:51 +03:00
|
|
|
arrayLen := len(data)
|
|
|
|
if arrayLen < 4 {
|
2020-11-30 19:02:50 +03:00
|
|
|
return -1
|
|
|
|
}
|
2020-11-30 19:26:51 +03:00
|
|
|
maxIter := int(uint(data[0]))
|
|
|
|
for i := 0; i < maxIter && i < arrayLen; i++ {
|
|
|
|
n := i % arrayLen
|
2020-11-30 19:02:50 +03:00
|
|
|
if n == 0 {
|
|
|
|
_ = rdb.Set(ctx, string(data[i:]), string(data[i:]), 0).Err()
|
|
|
|
} else if n == 1 {
|
|
|
|
_, _ = rdb.Get(ctx, string(data[i:])).Result()
|
|
|
|
} else if n == 2 {
|
|
|
|
_, _ = rdb.Incr(ctx, string(data[i:])).Result()
|
|
|
|
} else if n == 3 {
|
|
|
|
var cursor uint64
|
|
|
|
_, _, _ = rdb.Scan(ctx, cursor, string(data[i:]), 10).Result()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 1
|
|
|
|
}
|