fugue / regula

Regula checks infrastructure as code templates (Terraform, CloudFormation, k8s manifests) for AWS, Azure, Google Cloud, and Kubernetes security and compliance using Open Policy Agent/Rego

Home Page:https://regula.dev/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] panic: runtime error: invalid memory address or nil pointer dereference

lemeurherve opened this issue · comments

Describe the bug
Tried regula run . in a local clone of https://github.com/jenkins-infra/jenkins-infra containing puppet code and got this error:

$  jenkins-infra git:(production) regula run .                                            
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x15194d8]

goroutine 1 [running]:
github.com/fugue/regula/pkg/loader.(*CfnDetector).DetectFile(0xc0003ed8b0, {0x1d8cd48, 0xc000576a00}, {0xb, 0x0})
        github.com/fugue/regula/pkg/loader/cfn.go:45 +0x1d8
github.com/fugue/regula/pkg/loader.(*file).DetectType(0xc0003ed930, {0x1d79328, 0x2552348}, {0xc0, 0xe2})
        github.com/fugue/regula/pkg/loader/input.go:126 +0x34
github.com/fugue/regula/pkg/loader.(*AutoDetector).DetectFile(0xc0003ed950, {0x1d8cd48, 0xc000576a00}, {0xd, 0xb2})
        github.com/fugue/regula/pkg/loader/auto.go:37 +0xa3
github.com/fugue/regula/pkg/loader.(*file).DetectType(0xc0003ed960, {0x1d79300, 0xc0004ce1b0}, {0x1d, 0x0})
        github.com/fugue/regula/pkg/loader/input.go:126 +0x34
github.com/fugue/regula/pkg/loader.LocalConfigurationLoader.func1.1({0xa3e9098, 0xc000576a00})
        github.com/fugue/regula/pkg/loader/loadpaths.go:67 +0x98
github.com/fugue/regula/pkg/loader.(*directory).Walk(0xa3e90d0, 0xc00004b9e0)
        github.com/fugue/regula/pkg/loader/input.go:49 +0x7f
github.com/fugue/regula/pkg/loader.(*directory).Walk(0xa3e90d0, 0xc00004b9e0)
        github.com/fugue/regula/pkg/loader/input.go:57 +0xb3
github.com/fugue/regula/pkg/loader.(*directory).Walk(0x7ffeefbff68b, 0xc00004b9e0)
        github.com/fugue/regula/pkg/loader/input.go:57 +0xb3
github.com/fugue/regula/pkg/loader.LocalConfigurationLoader.func1()
        github.com/fugue/regula/pkg/loader/loadpaths.go:134 +0x5f5
github.com/fugue/regula/cmd.NewRunCommand.func1(0xc0002d8280, {0xc00043e210, 0x1, 0x1})
        github.com/fugue/regula/cmd/run.go:144 +0x777
github.com/spf13/cobra.(*Command).execute(0xc0002d8280, {0xc00043e1e0, 0x1, 0x1})
        github.com/spf13/cobra@v1.2.1/command.go:856 +0x60e
github.com/spf13/cobra.(*Command).ExecuteC(0x24ecd60)
        github.com/spf13/cobra@v1.2.1/command.go:974 +0x3bc
github.com/spf13/cobra.(*Command).Execute(...)
        github.com/spf13/cobra@v1.2.1/command.go:902
github.com/fugue/regula/cmd.Execute()
        github.com/fugue/regula/cmd/root.go:47 +0x25
main.main()
        github.com/fugue/regula/main.go:22 +0x17

I've also tried it on other repos with terraform, no problem.
Regula should probably fails properly on unsupported langages instead of crashing.

Operating System
MacOS 11.16.1

Steps to reproduce

git clone https://github.com/jenkins-infra/jenkins-infra
cd jenkins-infra
regula run .

Thank you for submitting this issue, @lemeurherve! The problem here was a missing nil check. The input in question was a YAML file which only contains a comment: https://github.com/jenkins-infra/jenkins-infra/blob/production/hieradata/clients/tomato.yaml. This was an edge case that we missed.

#314 should resolve this issue.

@jason-fugue cool, thanks for the quick resolution!