Skip to content

Commit

Permalink
More staticcheck + lint updates (#1574)
Browse files Browse the repository at this point in the history
  • Loading branch information
RebeccaMahany authored Feb 1, 2024
1 parent 782505f commit 4704d18
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 32 deletions.
20 changes: 9 additions & 11 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,24 @@ linters:
enable:
- bodyclose
- containedctx
- unused
- forbidigo
- gofmt
- govet
- ineffassign
- misspell
- nakedret
- sqlclosecheck
- unconvert
- paralleltest
- forbidigo
- sloglint
- revive
- sloglint
- sqlclosecheck
- staticcheck
- unconvert
- unused
disable:
- errcheck
- gosec
- gosimple
- ineffassign
- interfacer
- maligned
- noctx
- staticcheck
- structcheck
- varcheck

linters-settings:
errcheck:
Expand Down Expand Up @@ -67,6 +63,8 @@ linters-settings:
disabled: false
- name: confusing-naming
disabled: false
staticcheck:
checks: ["all"]

issues:
exclude-rules:
Expand Down
2 changes: 1 addition & 1 deletion ee/keyidentifier/keyidentifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (kIdentifer *KeyIdentifier) attemptPem(keyBytes []byte) (*KeyInfo, error) {

case "PRIVATE KEY":
// RFC5208 - https://tools.ietf.org/html/rfc5208
ki.Encrypted = boolPtr(x509.IsEncryptedPEMBlock(block))
ki.Encrypted = boolPtr(x509.IsEncryptedPEMBlock(block)) // nolint:staticcheck
if key, err := x509.ParsePKCS8PrivateKey(block.Bytes); err == nil {
switch assertedKey := key.(type) {
case *rsa.PrivateKey:
Expand Down
4 changes: 1 addition & 3 deletions ee/tables/crowdstrike/falconctl/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ func parseOptions(reader io.Reader) (any, error) {
kv[1] = strings.Trim(kv[1], `" `)

// Remove parenthetical note about an unset default
if strings.HasSuffix(kv[1], " (unset default)") {
kv[1] = kv[1][:len(kv[1])-len(" (unset default)")]
}
kv[1] = strings.TrimSuffix(kv[1], " (unset default)")

if lastKey == "rfm-reason" && kv[0] == "code" {
kv[0] = "rfm-reason-code"
Expand Down
2 changes: 1 addition & 1 deletion ee/tables/wifi_networks/wifi_networks.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TablePlugin(logger log.Logger) *table.Plugin {
}

func (t *Table) generate(ctx context.Context, queryContext table.QueryContext) ([]map[string]string, error) {
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
ctx, cancel := context.WithTimeout(ctx, 60*time.Second)
defer cancel()
var results []map[string]string
var output bytes.Buffer
Expand Down
2 changes: 1 addition & 1 deletion pkg/launcher/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ func ParseOptions(subcommandName string, args []string) (*Options, error) {
return nil, errors.New("both enroll_secret and enroll_secret_path were defined")
}

updateChannel := autoupdate.Stable
var updateChannel autoupdate.UpdateChannel
switch *flUpdateChannel {
case "", "stable":
updateChannel = autoupdate.Stable
Expand Down
17 changes: 14 additions & 3 deletions pkg/log/eventlog/writer_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,16 @@ func openHandle(host, source string) (h windows.Handle, err error) {
}
var s *uint16
if host != "" {
s = syscall.StringToUTF16Ptr(host)
s, err = syscall.UTF16PtrFromString(host)
if err != nil {
return h, err
}
}
h, err = windows.RegisterEventSource(s, syscall.StringToUTF16Ptr(source))
srcPtr, err := syscall.UTF16PtrFromString(source)
if err != nil {
return h, err
}
h, err = windows.RegisterEventSource(s, srcPtr)
return h, err
}

Expand All @@ -46,7 +53,11 @@ func (w *Writer) Close() error {
}

func (w *Writer) Write(p []byte) (n int, err error) {
ss := []*uint16{syscall.StringToUTF16Ptr(string(p))}
ptr, err := syscall.UTF16PtrFromString(string(p))
if err != nil {
return 0, err
}
ss := []*uint16{ptr}
// always report as Info. Launcher logs as either info or debug, but the event log does not
// appear to have a debug level.
err = windows.ReportEvent(w.handle, windows.EVENTLOG_INFORMATION_TYPE, 0, 1, 0, 1, 0, &ss[0], nil)
Expand Down
13 changes: 11 additions & 2 deletions pkg/osquery/table/program_icons_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,15 @@ func generateUninstallerProgramIcons() []map[string]string {
for key, paths := range uninstallRegPaths {
for _, path := range paths {
key, err := registry.OpenKey(key, path, registry.READ)
defer key.Close()
if err != nil {
continue
}
defer key.Close()

iconPath, _, err := key.GetStringValue("DisplayIcon")
if err != nil {
continue
}
icon, err := parseIcoFile(iconPath)
if err != nil {
continue
Expand Down Expand Up @@ -93,12 +96,15 @@ func generateInstallersProgramIcons() []map[string]string {
for key, paths := range productRegPaths {
for _, path := range paths {
key, err := registry.OpenKey(key, path, registry.READ)
defer key.Close()
if err != nil {
continue
}
defer key.Close()

iconPath, _, err := key.GetStringValue("ProductIcon")
if err != nil {
continue
}
icon, err := parseIcoFile(iconPath)
if err != nil {
continue
Expand Down Expand Up @@ -126,6 +132,9 @@ func generateInstallersProgramIcons() []map[string]string {
func parseIcoFile(fullPath string) (icon, error) {
var programIcon icon
expandedPath, err := registry.ExpandString(fullPath)
if err != nil {
return programIcon, err
}
icoReader, err := os.Open(expandedPath)
if err != nil {
return programIcon, err
Expand Down
4 changes: 1 addition & 3 deletions pkg/osquery/table/user_avatar_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ func (t *userAvatarTable) generateAvatars(ctx context.Context, queryContext tabl
}
} else {
usernamesString := C.LocalUsers()
for _, posixName := range strings.Split(C.GoString(usernamesString), " ") {
usernames = append(usernames, posixName)
}
usernames = append(usernames, strings.Split(C.GoString(usernamesString), " ")...)
}

var results []map[string]string
Expand Down
2 changes: 1 addition & 1 deletion pkg/packagekit/wix/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const (
type StartType string

const (
StartAuto StartType = "auto"
StartAuto StartType = "auto" // nolint:staticcheck // TODO FIXME
StartDemand = "demand"
StartDisabled = "disabled"
StartBoot = "boot"
Expand Down
14 changes: 8 additions & 6 deletions pkg/service/client_grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"

"github.com/kolide/launcher/ee/agent/types"
pb "github.com/kolide/launcher/pkg/pb/launcher"
Expand Down Expand Up @@ -97,7 +98,7 @@ func NewGRPCClient(k types.Knapsack, conn *grpc.ClientConn) KolideService {
return client
}

// dialGRPC creates a grpc client connection.
// DialGRPC creates a grpc client connection.
func DialGRPC(
k types.Knapsack,
rootPool *x509.CertPool,
Expand All @@ -111,19 +112,20 @@ func DialGRPC(
"cert_pinning", len(k.CertPins()) > 0,
)

grpcOpts := []grpc.DialOption{
grpc.WithTimeout(time.Second),
}
grpcCtx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()

grpcOpts := []grpc.DialOption{}
if k.InsecureTransportTLS() {
grpcOpts = append(grpcOpts, grpc.WithInsecure())
grpcOpts = append(grpcOpts, grpc.WithTransportCredentials(insecure.NewCredentials()))
} else {
creds := &tlsCreds{credentials.NewTLS(makeTLSConfig(k, rootPool))}
grpcOpts = append(grpcOpts, grpc.WithTransportCredentials(creds))
}

grpcOpts = append(grpcOpts, opts...)

conn, err := grpc.Dial(k.KolideServerURL(), grpcOpts...)
conn, err := grpc.DialContext(grpcCtx, k.KolideServerURL(), grpcOpts...)
return conn, err
}

Expand Down

0 comments on commit 4704d18

Please sign in to comment.