Skip to content

Commit

Permalink
🐛 fixing panics that occurred in the windup-shim (#375)
Browse files Browse the repository at this point in the history
Signed-off-by: Shawn Hurley <[email protected]>
  • Loading branch information
shawn-hurley committed Oct 13, 2023
1 parent ff41588 commit 539de46
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 4 additions & 1 deletion engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,9 +432,12 @@ func (r *ruleEngine) createViolation(ctx context.Context, conditionResponse Cond

for _, cv := range rule.CustomVariables {
match := cv.Pattern.FindStringSubmatch(originalCodeSnip)
if cv.NameOfCaptureGroup != "" && cv.Pattern.SubexpIndex(cv.NameOfCaptureGroup) < len(match) {
if cv.NameOfCaptureGroup != "" && cv.Pattern.SubexpIndex(cv.NameOfCaptureGroup) >= 0 &&
cv.Pattern.SubexpIndex(cv.NameOfCaptureGroup) < len(match) {

m.Variables[cv.Name] = strings.TrimSpace(match[cv.Pattern.SubexpIndex(cv.NameOfCaptureGroup)])
continue

} else {
switch len(match) {
case 0:
Expand Down
8 changes: 8 additions & 0 deletions provider/internal/java/dependency.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"os"
"os/exec"
"path/filepath"
"reflect"
"regexp"
"strings"

Expand Down Expand Up @@ -111,6 +112,10 @@ func (p *javaServiceClient) GetDependenciesFallback(ctx context.Context, locatio
if err != nil {
return nil, err
}
// If the pom object is empty then parse failed silently.
if reflect.DeepEqual(*pom, gopom.Project{}) {
return nil, nil
}

// have to get both <dependencies> and <dependencyManagement> dependencies (if present)
var pomDeps []gopom.Dependency
Expand All @@ -125,6 +130,9 @@ func (p *javaServiceClient) GetDependenciesFallback(ctx context.Context, locatio

// add each dependency found
for _, d := range pomDeps {
if d.GroupID == nil || d.Version == nil || d.ArtifactID == nil {
continue
}
dep := provider.Dep{}
dep.Name = fmt.Sprintf("%s.%s", *d.GroupID, *d.ArtifactID)
if *d.Version != "" {
Expand Down

0 comments on commit 539de46

Please sign in to comment.