我正试图使用govulncheck tool扫描我的围棋模块中的漏洞.按照"Managing Go installations" page上的说明,我安装了两个GO版本:1.17.9和1.18.6:

$ go version
go version go1.17.9 linux/amd64
$ go1.18.6 version
go version go1.18.6 linux/amd64

我的模块是使用1.18.6构建和运行的.我使用GO 1.18.6使用以下命令安装了govulncheck:

$ go1.18.6 install golang.org/x/vuln/cmd/govulncheck@latest
go: downloading golang.org/x/vuln v0.0.0-20220913170424-c9fe2ba7ccad
go: downloading golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4
go: downloading golang.org/x/tools v0.1.13-0.20220803210227-8b9a1fbdf5c3
go: downloading golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e

但当我对我的模块运行govulncheck ./...时,它报告了GO 1.17.9的问题.

$ govulncheck ./...
govulncheck is an experimental tool. Share feedback at https://go.dev/s/govulncheck-feedback.

Scanning for dependencies with known vulnerabilities...
Found 5 known vulnerabilities.

Vulnerability #1: GO-2022-0524
  Calling Reader.Read on an archive containing a large number of
  concatenated 0-length compressed files can cause a panic due to
  stack exhaustion.

  Call stacks in your code:
      path/omitted/example.go:79:67: example.com/example-project/path/omitted/example.Method calls example.com/vulnerable-dependency/path/omitted/example.Foo.Bar, which eventually calls compress/gzip.Reader.Read

  Found in: compress/gzip@go1.17.9
  Fixed in: compress/gzip@go1.18.4
  More info: https://pkg.go.dev/vuln/GO-2022-0524

(etc)

这个示例问题已经在我使用的Go版本(1.18.6)中修复了,但是由于govulncheck使用的是1.17.9而不是1.18.6,它没有看到问题得到缓解.

如何使用我想要的Go版本运行此工具?

推荐答案

我将把我的 comments 写成一个(稍微详细一点)的答案:

根据the docs,governcheck将使用在路径上找到的go命令.因此,一种解决方案是仅在使用governcheck时导出不同的路径(go指向1.18.6,而不是1.17.9).

您可以在您的Makefile中很容易地做到这一点,如下所示:

vulncheck: export PATH:=$(PATH_TO_GO_1_18_6):$(PATH)
vulncheck:
     govulncheck ./...

Go相关问答推荐

迭代项列表时如何超时并发调用

有没有更简单的方法在Go中编写这个逻辑?

消费者在NAT中是如何实现的

如何使用GRPC UnaryClientInterceptor中的`maily`参数?

带有一个新变量的Go冒号等于运算符

错误&对象已被Golang在K8s操作符上修改

Date.Format正在输出非常奇怪的日期

无法获取RPC描述符

如何模拟 stripe 需要 webhooks 的捕获事件?

Go - 永远停止带有上下文的循环

命令行参数在 Golang 程序中不正确地接受为参数

golang yaml 马歇尔网址

使用 Grafana alert 在几分钟内重复alert

使用 go.work 文件在多个测试文件上运行 go test 命令

使用 AppID 在 Windows 中启动应用程序并获取 pid

如何使用 Status 字段创建 Kubernetes 对象?

自定义指标未显示在 prometheus web ui 中,grafana 中也是如此

使用 oklog/run 来自 Go 编译器的错误(无值)用作值

如何获取多个 url 参数值

Go lang - 惯用的默认后备