Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

processors: incorrect path regex normalization leads to panic #3277

Closed
4 tasks done
tdakkota opened this issue Oct 5, 2022 · 2 comments · Fixed by #3278
Closed
4 tasks done

processors: incorrect path regex normalization leads to panic #3277

tdakkota opened this issue Oct 5, 2022 · 2 comments · Fixed by #3278
Assignees
Labels
bug Something isn't working feedback required Requires additional feedback

Comments

@tdakkota
Copy link
Member

tdakkota commented Oct 5, 2022

Welcome

  • Yes, I'm using a binary release within 2 latest major releases. Only such installations are supported.
  • Yes, I've searched similar issues on GitHub and didn't find any.
  • Yes, I've included all information below (version, config, etc).
  • Yes, I've tried with the standalone linter if available. (https://golangci-lint.run/usage/linters/)

Description of the problem

It seems normalization introduced in #2387 generates incorrect regex.

I think this exclude rule leads to panic:

issues:
  exclude-use-default: false
  exclude-rules:
    # Ignore linters in main packages.
    - path: cmd\/.+\/main\.go
      linters: [ goconst, funlen, gocognit, gocyclo ]

v1.49.0 works fine.
*nix builds are unaffected, probably.

Version of golangci-lint

$ golangci-lint --version
golangci-lint has version v1.50.0 built from (unknown, mod sum: "h1:+Xmyt8rKLauNLp2gzcxKMN8VNGqGc5Avc2ZLTwIOpEA=") on (unknown)

Configuration file

https://github.com/ogen-go/ogen/blob/ded33e09c1697f41473e0defe69f345867e24375/.golangci.yml

linters-settings:
  gocyclo:
    min-complexity: 15
  maligned:
    suggest-new: true
  dupl:
    threshold: 120
  goconst:
    min-len: 2
    min-occurrences: 3
  misspell:
    locale: US
  lll:
    line-length: 140
  gocritic:
    enabled-tags:
      - diagnostic
      - experimental
      - opinionated
      - performance
      - style
    disabled-checks:
      - hugeParam
      - rangeValCopy
      - exitAfterDefer
      - whyNoLint
      - appendAssign
      - octalLiteral
      - httpNoBody
      - unnecessaryBlock # for UUID encoder
      - paramTypeCombine # https://github.com/go-critic/go-critic/issues/1248, waiting for 0.6.5 bundled with golangci-lint

linters:
  enable:
    - deadcode
    - depguard
    - dogsled
    - errcheck
    - goconst
    - gocritic
    - revive
    - gosec
    - govet
    - ineffassign
    - lll
    - misspell
    - nakedret
    - structcheck
    - typecheck
    - unconvert
    - unparam
    - varcheck
    - whitespace
    - unused
    # Do not enable:
    # - wsl       (too opinionated about newlines)
    # - godox     (todos are OK)
    # - bodyclose (false positives on helper functions)
    # - prealloc  (not worth it in scope of this project)
    # - maligned  (same as prealloc)
    # - funlen    (gocyclo is enough)
    # - gochecknoglobals (we know when it is ok to use globals)
    # - gochecknoinits (we know when it is ok to use inits)
    # - dupl (validator/parser package are false positive)


issues:
  exclude-use-default: false
  exclude-rules:
    # Exclude go:generate from lll
    - source: "//go:generate"
      linters: [ lll ]

    # Exclude links from lll
    - source: "// See https://"
      linters: [ lll ]

    # Disable linters that are annoying in tests.
    - path: _test\.go
      linters:
        - gocyclo
        - errcheck
        - dupl
        - gosec
        - funlen
        - goconst
        - gocognit
        - scopelint
        - lll
    - path: _test\.go
      linters: [ unparam ]
      text: .*\$\d? # Do not warn about unused closure parameters in test files.

    # Ignore shadowing of err.
    - linters: [ govet ]
      text: 'declaration of "(err|ctx|log)"'

    # Ignore linters in main packages.
    - path: cmd\/.+\/main\.go
      linters: [ goconst, funlen, gocognit, gocyclo ]

    # TODO(tdakkota): add comments?
    - path: (conv|uri|gen|otelogen)
      linters: [ revive, golint ]
      text: "(should have comment.+or be unexported|comment on exported)"

    # We don't need package comments for internal packages.
    # We don't need comments for command packages.
    - path: .*(cmd|tools|internal)(\/|\\).*
      linters: [ revive, golint ]
      text: "should have (comment.+or be unexported|a package comment)"

    # Intended in commands:
    # G307: Deferring unsafe method "Close" on type "*os.File"
    # G304: Potential file inclusion via variable
    - path: .*(cmd|tools)(\/|\\).+(\/|\\).+\.go
      text: G(304|306|307)

    # Nobody cares.
    # G114: Use of net/http serve function that has no support for setting timeouts
    - path: techempower(\/|\\)main.go
      text: G114

    # We are using quoting algorithm from mime/multipart package. False-positive.
    - path: http(\/|\\)file\.go
      linters: [ gocritic ]
      text: sprintfQuotedString

    # Not supposed to be constant.
    - linters: [ goconst ]
      text: 'string `(string|number|u?int\d{0,2})`'
    - linters: [ goconst ]
      text: 'string `(Unix|unix|date|time)'

    - linters: [ revive ]
      text: "if-return: redundant if ...; err != nil check, just return error instead."

Go environment

$ go version
go version go1.19.2 windows/amd64

Verbose output of running

$ golangci-lint cache clean
$ golangci-lint run -v
level=info msg="[config_reader] Used config file .golangci.yml"
level=info msg="[lintersdb] Active 22 linters: [deadcode depguard dogsled errcheck goconst gocritic gosec gosimple govet ineffassign lll misspell nakedret revive staticcheck structcheck typecheck unconvert unparam unused varcheck wh
itespace]"
level=info msg="[loader] Go packages loading at mode 575 (imports|types_sizes|compiled_files|deps|name|exports_file|files) took 3.065513s"
level=warning msg="[runner] The linter 'varcheck' is deprecated (since v1.49.0) due to: The owner seems to have abandoned the linter.  Replaced by unused."
level=warning msg="[runner] The linter 'structcheck' is deprecated (since v1.49.0) due to: The owner seems to have abandoned the linter.  Replaced by unused."
level=warning msg="[runner] The linter 'deadcode' is deprecated (since v1.49.0) due to: The owner seems to have abandoned the linter.  Replaced by unused."
level=info msg="[runner/filename_unadjuster] Pre-built 0 adjustments in 270.7187ms"
level=info msg="Memory: 36 samples, avg is 28.6MB, max is 51.6MB"
level=info msg="Execution took 3.4041123s"
panic: regexp: Compile(`cmd\\\.+\\\main\.go`): error parsing regexp: invalid escape sequence: `\m`

goroutine 1 [running]:
regexp.MustCompile({0xc0006f1218, 0x13})
        C:/scoop/apps/go/current/src/regexp/regexp.go:319 +0xbb
github.com/golangci/golangci-lint/pkg/result/processors.createRules({0xc0001a2900, 0xe, 0x1a0edd20150?}, {0xe50638, 0x4})
        C:/go/pkg/mod/github.com/golangci/golangci-lint@v1.50.0/pkg/result/processors/exclude_rules.go:48 +0x23c
github.com/golangci/golangci-lint/pkg/result/processors.NewExcludeRules(...)
        C:/go/pkg/mod/github.com/golangci/golangci-lint@v1.50.0/pkg/result/processors/exclude_rules.go:30
github.com/golangci/golangci-lint/pkg/lint.getExcludeRulesProcessor(0xc000829cc8, {0x10d6490, 0xc0013b91a0}, 0xc00085bc20)
        C:/go/pkg/mod/github.com/golangci/golangci-lint@v1.50.0/pkg/lint/runner.go:294 +0x348
github.com/golangci/golangci-lint/pkg/lint.NewRunner(0xc000829000, {0x10d6490?, 0xc0013b91a0}, 0x273f87?, 0xc00085bb60, 0xc00085bc20, 0xc0000914a0, {0xc0013d4400, 0x2c, 0x40})
        C:/go/pkg/mod/github.com/golangci/golangci-lint@v1.50.0/pkg/lint/runner.go:86 +0x430
github.com/golangci/golangci-lint/pkg/commands.(*Executor).runAnalysis(0xc00012d200, {0x10d0f28, 0xc000882cc0}, {0xc000882ba0?, 0x19116c0?, 0x10d0f28?})
        C:/go/pkg/mod/github.com/golangci/golangci-lint@v1.50.0/pkg/commands/run.go:362 +0x485
github.com/golangci/golangci-lint/pkg/commands.(*Executor).runAndPrint(0xc00012d200, {0x10d0f28, 0xc000882cc0}, {0xc000882ba0, 0x1, 0x6})
        C:/go/pkg/mod/github.com/golangci/golangci-lint@v1.50.0/pkg/commands/run.go:409 +0x1e9
github.com/golangci/golangci-lint/pkg/commands.(*Executor).executeRun(0xc00012d200, 0x0?, {0xc000882ba0, 0x1, 0x6})
        C:/go/pkg/mod/github.com/golangci/golangci-lint@v1.50.0/pkg/commands/run.go:522 +0x245
github.com/spf13/cobra.(*Command).execute(0xc000407680, {0xc000882b40, 0x6, 0x6})
        C:/go/pkg/mod/github.com/spf13/cobra@v1.5.0/command.go:876 +0x67b
github.com/spf13/cobra.(*Command).ExecuteC(0xc000407400)
        C:/go/pkg/mod/github.com/spf13/cobra@v1.5.0/command.go:990 +0x3bd
github.com/spf13/cobra.(*Command).Execute(...)
        C:/go/pkg/mod/github.com/spf13/cobra@v1.5.0/command.go:918
github.com/golangci/golangci-lint/pkg/commands.(*Executor).Execute(...)
        C:/go/pkg/mod/github.com/golangci/golangci-lint@v1.50.0/pkg/commands/executor.go:146
main.main()
        C:/go/pkg/mod/github.com/golangci/golangci-lint@v1.50.0/cmd/golangci-lint/main.go:21 +0x4f

Code example or link to a public repository

https://github.com/ogen-go/ogen/

@tdakkota tdakkota added the bug Something isn't working label Oct 5, 2022
@boring-cyborg
Copy link

boring-cyborg bot commented Oct 5, 2022

Hey, thank you for opening your first Issue ! 🙂 If you would like to contribute we have a guide for contributors.

@ldez ldez self-assigned this Oct 5, 2022
@ldez
Copy link
Member

ldez commented Oct 5, 2022

Hello,

you don't have to escape / because / is not a special character.

Can you clean your regular expressions? (You have to replace \/ with /)

@ldez ldez added the feedback required Requires additional feedback label Oct 5, 2022
@ldez ldez closed this as completed in #3278 Oct 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working feedback required Requires additional feedback
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants