chore: add golangci-lint config and fix all lint issues
Enable 15 additional linters (gosec, errorlint, gocritic, modernize, misspell, bodyclose, sqlclosecheck, nilerr, unconvert, durationcheck, sloglint, wastedassign, usestdlibvars) with sensible exclusion rules. Fix all findings: errors.Is for error comparisons, run() pattern in main to avoid exitAfterDefer, ReadHeaderTimeout for Slowloris protection, bounds check in escape sequence reader, WaitGroup.Go, slices.Contains, range-over-int loops, and http.MethodGet constants. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,7 @@ package bash
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
@@ -55,7 +56,7 @@ func (b *BashShell) Handle(ctx context.Context, sess *shell.SessionContext, rw i
|
||||
}
|
||||
|
||||
line, err := readLine(ctx, rw)
|
||||
if err == io.EOF {
|
||||
if errors.Is(err, io.EOF) {
|
||||
fmt.Fprint(rw, "logout\r\n")
|
||||
return nil
|
||||
}
|
||||
@@ -81,7 +82,9 @@ func (b *BashShell) Handle(ctx context.Context, sess *shell.SessionContext, rw i
|
||||
|
||||
// Log command and output to store.
|
||||
if sess.Store != nil {
|
||||
sess.Store.AppendSessionLog(ctx, sess.SessionID, trimmed, output)
|
||||
if err := sess.Store.AppendSessionLog(ctx, sess.SessionID, trimmed, output); err != nil {
|
||||
return fmt.Errorf("append session log: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
if result.exit {
|
||||
@@ -145,8 +148,7 @@ func readLine(ctx context.Context, rw io.ReadWriter) (string, error) {
|
||||
// Read and discard the rest of the escape sequence.
|
||||
// Most are 3 bytes: ESC [ X (arrow keys, etc.)
|
||||
next := make([]byte, 1)
|
||||
rw.Read(next)
|
||||
if next[0] == '[' {
|
||||
if n, _ := rw.Read(next); n > 0 && next[0] == '[' {
|
||||
rw.Read(next) // read the final byte
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package bash
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"io"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -108,7 +109,7 @@ func TestReadLineCtrlD(t *testing.T) {
|
||||
|
||||
ctx := context.Background()
|
||||
_, err := readLine(ctx, rw)
|
||||
if err != io.EOF {
|
||||
if !errors.Is(err, io.EOF) {
|
||||
t.Fatalf("expected io.EOF, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user