From b0a539ca994a3b51fdad9e0d5ff1ca9a5c94e183 Mon Sep 17 00:00:00 2001 From: dingjun Date: Thu, 1 Sep 2022 15:55:06 +0800 Subject: [PATCH] fix static check warnings --- client.go | 10 ++++------ console.go | 1 + console_unix.go | 1 + obfssh/ssh.go | 15 +++++---------- obfsshd/server.go | 2 +- redir.go | 1 + redir_iptables.go | 1 + redir_iptables_2.go | 1 + server.go | 14 ++++++-------- 9 files changed, 21 insertions(+), 25 deletions(-) diff --git a/client.go b/client.go index b0c3121..ad9b4a1 100644 --- a/client.go +++ b/client.go @@ -38,8 +38,6 @@ type Client struct { // addr is server address // // conf is the client configure -// -// func NewClient(c net.Conn, config *ssh.ClientConfig, addr string, conf *Conf) (*Client, error) { //obfsConn := &TimedOutConn{c, conf.Timeout} sshConn, newch, reqs, err := ssh.NewClientConn(c, addr, config) @@ -73,9 +71,8 @@ func (cc *Client) Run() error { go cc.registerSignal() - select { - case <-time.After(1 * time.Second): - } + time.Sleep(1 * time.Second) + // wait port forward to finish if cc.listeners != nil { log.Debugf("wait all channel to be done") @@ -420,7 +417,8 @@ func (cc *Client) registerSignal() { } // AddDynamicHTTPForward add a http dynamic forward through -// secure channel +// +// secure channel func (cc *Client) AddDynamicHTTPForward(addr string) error { log.Debugf("add dynamic http listen: %s", addr) l, err := net.Listen("tcp", addr) diff --git a/console.go b/console.go index 45b7186..0387069 100644 --- a/console.go +++ b/console.go @@ -1,3 +1,4 @@ +//go:build windows // +build windows package obfssh diff --git a/console_unix.go b/console_unix.go index d0beed9..21f6afd 100644 --- a/console_unix.go +++ b/console_unix.go @@ -1,3 +1,4 @@ +//go:build darwin || freebsd || linux || openbsd || solaris // +build darwin freebsd linux openbsd solaris package obfssh diff --git a/obfssh/ssh.go b/obfssh/ssh.go index 2c94dca..a42c79c 100644 --- a/obfssh/ssh.go +++ b/obfssh/ssh.go @@ -233,13 +233,11 @@ func main() { timeout := time.Duration(cfg.KeepaliveInterval*2) * time.Second - var _conn = c - - conn := &obfssh.TimedOutConn{Conn: c, Timeout: timeout} + var _conn net.Conn = &obfssh.TimedOutConn{Conn: c, Timeout: timeout} if cfg.TLS { log.Debugf("begin tls handshake") - _conn = tls.Client(conn, &tls.Config{ + _conn = tls.Client(_conn, &tls.Config{ ServerName: host, InsecureSkipVerify: cfg.TLSInsecure, }) @@ -310,7 +308,7 @@ func main() { } for _, p := range cfg.DynamicForwards { - if strings.Index(p, ":") == -1 { + if !strings.Contains(p, ":") { local = fmt.Sprintf(":%s", p) } else { local = p @@ -322,7 +320,7 @@ func main() { } for _, p := range cfg.DynamicHTTP { - if strings.Index(p, ":") == -1 { + if !strings.Contains(p, ":") { local = fmt.Sprintf(":%s", p) } else { local = p @@ -363,10 +361,7 @@ func main() { func parseForwardAddr(s string) []string { ss := strings.FieldsFunc(s, func(c rune) bool { - if c == ':' { - return true - } - return false + return c == ':' }) return ss } diff --git a/obfsshd/server.go b/obfsshd/server.go index eb82858..eaa1f43 100644 --- a/obfsshd/server.go +++ b/obfsshd/server.go @@ -74,7 +74,7 @@ func main() { if u, err := conf.getUser(c.User()); err == nil { for _, pk := range u.publicKeys { if k.Type() == pk.Type() && - bytes.Compare(k.Marshal(), pk.Marshal()) == 0 { + bytes.Equal(k.Marshal(), pk.Marshal()) { return true } } diff --git a/redir.go b/redir.go index 76419a0..caf59a2 100644 --- a/redir.go +++ b/redir.go @@ -1,3 +1,4 @@ +//go:build !linux // +build !linux package obfssh diff --git a/redir_iptables.go b/redir_iptables.go index 23c1fef..fab7e8e 100644 --- a/redir_iptables.go +++ b/redir_iptables.go @@ -1,3 +1,4 @@ +//go:build linux && !cgo // +build linux,!cgo package obfssh diff --git a/redir_iptables_2.go b/redir_iptables_2.go index d0e7532..cb89f88 100644 --- a/redir_iptables_2.go +++ b/redir_iptables_2.go @@ -1,3 +1,4 @@ +//go:build linux && cgo // +build linux,cgo package obfssh diff --git a/server.go b/server.go index d8936ff..6ca2416 100644 --- a/server.go +++ b/server.go @@ -34,8 +34,6 @@ type Server struct { // config is &ssh.ServerConfig // // conf is the server configure -// -// func NewServer(c net.Conn, config *ssh.ServerConfig, conf *Conf) (*Server, error) { sshConn, ch, req, err := ssh.NewServerConn(&TimedOutConn{c, 15 * 60 * time.Second}, config) if err != nil { @@ -211,10 +209,10 @@ func (s *session) handleSubsystem(payload []byte) bool { func (s *session) handleShell() bool { var cmd *exec.Cmd if runtime.GOOS == "windows" { - s.env = append(s.env, fmt.Sprintf("SHELL=powershell")) + s.env = append(s.env, "SHELL=powershell") cmd = exec.Command("powershell") } else { - s.env = append(s.env, fmt.Sprintf("SHELL=/bin/bash")) + s.env = append(s.env, "SHELL=/bin/bash") cmd = exec.Command("/bin/bash", "-l") } s.cmd = cmd @@ -232,10 +230,10 @@ func (s *session) handleExec(payload []byte) bool { } log.Infoln("execute command", _cmd.Arg) if runtime.GOOS == "windows" { - s.env = append(s.env, fmt.Sprintf("SHELL=powershell")) + s.env = append(s.env, "SHELL=powershell") cmd = exec.Command("powershell", "-Command", _cmd.Arg) } else { - s.env = append(s.env, fmt.Sprintf("SHELL=/bin/bash")) + s.env = append(s.env, "SHELL=/bin/bash") cmd = exec.Command("/bin/bash", "-c", _cmd.Arg) } s.cmd = cmd @@ -273,7 +271,7 @@ func (s *session) handlePtyReq(payload []byte) bool { s.env = append(s.env, fmt.Sprintf("SSH_TTY=%s", s.ptsname)) s.env = append(s.env, fmt.Sprintf("TERM=%s", _ptyReq.Term)) - ws, err := s._console.Size() + ws, _ := s._console.Size() log.Debugf("current console %+v", ws) ws.Height = uint16(_ptyReq.Rows) ws.Width = uint16(_ptyReq.Columns) @@ -566,7 +564,7 @@ func (sc *Server) handleTcpipForward(req *ssh.Request) { return } - if addr.Port > 65535 || addr.Port < 0 { + if addr.Port > 65535 { log.Errorf("invalid port %d", addr.Port) if req.WantReply { req.Reply(false, nil)