Don't crash when the packet length is zero

This commit is contained in:
Cassondra Foesch 2025-03-04 14:05:25 +00:00
parent f9e6b36c06
commit 1d50cfbc6c
1 changed files with 27 additions and 0 deletions

27
fuzz.go Normal file
View File

@ -0,0 +1,27 @@
// go:build gofuzz
//go:build gofuzz
// +build gofuzz
package sftp
import (
"bytes"
"context"
)
type sinkfuzz struct{}
func (*sinkfuzz) Close() error { return nil }
func (*sinkfuzz) Write(p []byte) (int, error) { return len(p), nil }
var devnull = &sinkfuzz{}
// To run: go-fuzz-build && go-fuzz
func Fuzz(data []byte) int {
c, err := NewClientPipe(context.Background(), bytes.NewReader(data), devnull)
if err != nil {
return 0
}
c.Close()
return 1
}