简体   繁体   English

gosec 给出“无法导入 C(C 没有元数据)”golang 错误

[英]gosec giving “could not import C (no metadata for C)” golang error

I am running gosec on my project but it gives following error due to which our pipeline is failing我在我的项目上运行 gosec 但它给出了以下错误,因为我们的管道失败了

Golang errors in file: [/home/usr/exmaple/project.go]:文件中的 Golang 错误:[/home/usr/exmaple/project.go]:

[line 22: column 8] - could not import C (no metadata for C) [第 22 行:第 8 列] - 无法导入 C(没有 C 的元数据)

While go build command successfully builds the project means there is no golang error.而 go 构建命令成功构建项目意味着没有 golang 错误。

This seems to be a bug encoutered by other people as well.这似乎也是其他人遇到的错误。 See this issue or this one .请参阅此问题问题。 You should probably report an issue to gosec as well for this.您可能也应该为此向 gosec 报告问题。 Or maybe about the go/packages package in the Go repo directly.或者可能直接在 Go 存储库中的go/packages package 。

This is not an issue.这不是问题。

We found out that our C code is present in.c and.h files in package directory, where.h file containing only function prototypes. We found out that our C code is present in.c and.h files in package directory, where.h file containing only function prototypes. And we are including only.h file in go files (cgo).我们在 go 文件 (cgo) 中包含 only.h 文件。

go build and go test commands are working because both of these commands when see.c and.h in package directory, compiles and link them. go build and go test commands are working because both of these commands when see.c and.h in package directory, compiles and link them. But gosec is a SAST tool, it doesn't compile.c and.h files present in package directory due to this gosec scan was getting only function prototypes not definition and was throwing Golang error could not import C (no metadata for C). But gosec is a SAST tool, it doesn't compile.c and.h files present in package directory due to this gosec scan was getting only function prototypes not definition and was throwing Golang error could not import C (no metadata for C).

Including the whole code in comments (CGO) worked.在注释中包含整个代码 (CGO) 有效。 Now gosec works fine.现在 gosec 工作正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM