// Fuzz is the interface for the go-fuzz. func Fuzz(data []byte) int { frd := &fakeRandChannel{bytes.NewReader(data), 0} err := sftpd.ServeChannel(frd, sftpd.EmptyFS{}) if err != nil { return 0 } if frd.nw >= 10 { return 2 } return 1 }
func handleConn(conn net.Conn, config *ssh.ServerConfig, fs sftpd.FileSystem) error { sc, chans, reqs, e := ssh.NewServerConn(conn, config) if e != nil { return e } defer sc.Close() // The incoming Request channel must be serviced. go PrintDiscardRequests(reqs) // Service the incoming Channel channel. for newChannel := range chans { if newChannel.ChannelType() != "session" { newChannel.Reject(ssh.UnknownChannelType, "unknown channel type") continue } channel, requests, err := newChannel.Accept() if err != nil { return err } go func(in <-chan *ssh.Request) { for req := range in { ok := false switch { case sftpd.IsSftpRequest(req): ok = true go func() { e := sftpd.ServeChannel(channel, fs) if e != nil { log.Println("sftpd servechannel failed:", e) } }() } req.Reply(ok, nil) } }(requests) } return nil }