Skip to content
This repository has been archived by the owner on Oct 10, 2023. It is now read-only.

Regular expressions in port detection might panic #220

Closed
rm3l opened this issue May 23, 2023 · 5 comments · Fixed by #238
Closed

Regular expressions in port detection might panic #220

rm3l opened this issue May 23, 2023 · 5 comments · Fixed by #238
Assignees
Labels
kind/bug Something isn't working

Comments

@rm3l
Copy link
Member

rm3l commented May 23, 2023

Which area this feature is related to?

/kind bug

What versions of software are you using?

Go project

Operating System and version:
Fedora 38

Go Pkg Version:
We are currently using Alizer on a1115da, but I locally tested by using the latest commit (59b155e), and the issue still persists.

Bug Summary

Describe the bug:

Tried to run odo analyze against https://github.com/backstage/backstage.
odo analyze is basically a wrapper around Alizer for Devfile, port and component name detection.

To Reproduce:

git clone https://github.com/backstage/backstage
cd backstage
# Install odo: https://odo.dev/docs/overview/installation
odo analyze -o json

Expected behavior

Not panicking, but returning an appropriate error to the caller, so they can handle it.

Any logs, error output, screenshots etc? Provide the devfile that sees this bug, if applicable

$ odo analyze -o json
                                                                                                                                      
panic: regexp: Compile("(let|const|var)\\s+{\n      onUnhandledRequest: ({ headers }\\s*=\\s*([^;]*)"): error parsing regexp: missing closing ): `(let|const|var)\s+{                          
      onUnhandledRequest: ({ headers }\s*=\s*([^;]*)`

goroutine 71 [running]:
regexp.MustCompile({0xc000b4bc70, 0x48})
        /home/asoro/.asdf/installs/golang/1.19.6/go/src/regexp/regexp.go:319 +0xbb
github.com/redhat-developer/alizer/go/pkg/apis/enricher/framework/javascript/nodejs.getPort({0xc000744c80, 0xc6d}, {0xc000b81d80, 0x111f11f?, 0x33acb6e?})
        /home/asoro/work/projects/odo/vendor/github.com/redhat-developer/alizer/go/pkg/apis/enricher/framework/javascript/nodejs/express_detector.go:86 +0x199
github.com/redhat-developer/alizer/go/pkg/apis/enricher/framework/javascript/nodejs.ExpressDetector.DoPortsDetection({}, 0xc0000c3a90, 0xd?)
        /home/asoro/work/projects/odo/vendor/github.com/redhat-developer/alizer/go/pkg/apis/enricher/framework/javascript/nodejs/express_detector.go:51 +0x20b
github.com/redhat-developer/alizer/go/pkg/apis/enricher.JavaScriptEnricher.DoEnrichComponent({}, 0xc0000c3a90, {{0xc00005c184, 0x1e}, {0xc000a98b10, 0x3, 0x3}}, 0x4cc5010?)
        /home/asoro/work/projects/odo/vendor/github.com/redhat-developer/alizer/go/pkg/apis/enricher/javascript_enricher.go:94 +0x5e8
github.com/redhat-developer/alizer/go/pkg/apis/recognizer.enrichComponent(0xc0000c3a90, {{0xc00005c184, 0x1e}, {0xc000a98b10, 0x3, 0x3}}, 0xc000492150?)
        /home/asoro/work/projects/odo/vendor/github.com/redhat-developer/alizer/go/pkg/apis/recognizer/component_recognizer.go:331 +0x89
github.com/redhat-developer/alizer/go/pkg/apis/recognizer.detectComponentByAnalyzingConfigFile({0xc000a33680, 0x41}, {0xc000867610, 0xa}, {{0xc00005c184, 0x1e}, {0xc000a98b10, 0x3, 0x3}}, 0xc000ac6050)
        /home/asoro/work/projects/odo/vendor/github.com/redhat-developer/alizer/go/pkg/apis/recognizer/component_recognizer.go:303 +0x3ae
github.com/redhat-developer/alizer/go/pkg/apis/recognizer.detectComponentUsingConfigFile({0xc000a33680, 0x41}, {0xc00080de40?, 0x2, 0x2}, {{0xc00005c184, 0x1e}, {0xc000a98b10, 0x3, 0x3}}, ...)
        /home/asoro/work/projects/odo/vendor/github.com/redhat-developer/alizer/go/pkg/apis/recognizer/component_recognizer.go:316 +0x15a
github.com/redhat-developer/alizer/go/pkg/apis/recognizer.DetectComponentsFromFilesList({0xc0010b6000, 0x2b50, 0xc000ac6050?}, {{0xc00005c184, 0x1e}, {0xc000a98b10, 0x3, 0x3}}, 0xc000a98b10?)
        /home/asoro/work/projects/odo/vendor/github.com/redhat-developer/alizer/go/pkg/apis/recognizer/component_recognizer.go:229 +0x327
github.com/redhat-developer/alizer/go/pkg/apis/recognizer.detectComponentsWithSettings({{0xc00005c184, 0x1e}, {0xc000a98b10, 0x3, 0x3}}, 0x4b4e680?)
        /home/asoro/work/projects/odo/vendor/github.com/redhat-developer/alizer/go/pkg/apis/recognizer/component_recognizer.go:86 +0xa5
github.com/redhat-developer/alizer/go/pkg/apis/recognizer.detectComponentsWithPathAndPortStartegy(...)
        /home/asoro/work/projects/odo/vendor/github.com/redhat-developer/alizer/go/pkg/apis/recognizer/component_recognizer.go:55
github.com/redhat-developer/alizer/go/pkg/apis/recognizer.DetectComponents({0xc00005c184, 0x1e})
        /home/asoro/work/projects/odo/vendor/github.com/redhat-developer/alizer/go/pkg/apis/recognizer/component_recognizer.go:34 +0xd1
github.com/redhat-developer/odo/pkg/alizer.(*Alizer).DetectPorts(0x34442f0?, {0xc00005c184, 0x1e})
        /home/asoro/work/projects/odo/pkg/alizer/alizer.go:128 +0x2d
github.com/redhat-developer/odo/pkg/init/backend.(*AlizerBackend).SelectDevfile.func1.1(0xc000699ae0, {0x380a598, 0xc000992fc0}, {0xc00005c184, 0x1e})
        /home/asoro/work/projects/odo/pkg/init/backend/alizer.go:57 +0x3af
github.com/redhat-developer/odo/pkg/init/backend.(*AlizerBackend).SelectDevfile.func1()
        /home/asoro/work/projects/odo/pkg/init/backend/alizer.go:80 +0x36
created by github.com/redhat-developer/odo/pkg/init/backend.(*AlizerBackend).SelectDevfile
        /home/asoro/work/projects/odo/pkg/init/backend/alizer.go:46 +0x12a

Additional context

Observed in the following issues:

Any workaround?

Suggestion on how to fix the bug

We guessed Alizer should take care with regexp.MustCompile when the regular expression is dynamic.

@openshift-ci openshift-ci bot added the kind/bug Something isn't working label May 23, 2023
@thepetk thepetk self-assigned this Jun 14, 2023
@thepetk
Copy link
Collaborator

thepetk commented Jun 15, 2023

Target Date: 28 June 2023

FYI Just started working on the issue :)

@rm3l
Copy link
Member Author

rm3l commented Jun 15, 2023

Target Date: 28 June 2023

FYI Just started working on the issue :)

Thanks for the heads-up, @thepetk !

@thepetk
Copy link
Collaborator

thepetk commented Jun 18, 2023

I've created a PR to replace MustCompile where we use dynamic string.

@thepetk
Copy link
Collaborator

thepetk commented Jun 19, 2023

@rm3l the pr is now merged. I've also put a test for this case in order to ensure that we are always covering this.

@rm3l
Copy link
Member Author

rm3l commented Jun 20, 2023

@rm3l the pr is now merged. I've also put a test for this case in order to ensure that we are always covering this.

Thanks @thepetk for the prompt fix! We'll update Alizer in odo then.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/bug Something isn't working
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants