forked from redis/go-redis
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request redis#1570 from AdamKorcz/fuzz1
Add fuzzer to integrate go-redis into OSS-fuzz
- Loading branch information
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// +build gofuzz | ||
|
||
package redis | ||
|
||
import ( | ||
"context" | ||
"time" | ||
) | ||
|
||
var ( | ||
ctx = context.Background() | ||
rdb *Client | ||
) | ||
|
||
func init() { | ||
rdb = NewClient(&Options{ | ||
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 { | ||
arrayLen := len(data) | ||
if arrayLen < 4 { | ||
return -1 | ||
} | ||
maxIter := int(uint(data[0])) | ||
for i := 0; i < maxIter && i < arrayLen; i++ { | ||
n := i % arrayLen | ||
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 | ||
} |