Skip to content

Commit

Permalink
Fixed errors and removed duplicates
Browse files Browse the repository at this point in the history
Signed-off-by: nathannaveen <[email protected]>
  • Loading branch information
nathannaveen committed Sep 30, 2024
1 parent f292dbc commit 52c423f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
15 changes: 9 additions & 6 deletions cmd/guacone/cmd/vulnerability.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func printVulnInfo(ctx context.Context, gqlclient graphql.Client, t table.Writer
logger.Fatalf("error searching via hasSBOM for package: %v", err)
}

if len(depVulnPaths) == 0 {
if len(depVulnPaths) == 0 && opts.inputType == purlType {
depVulnPaths, depVulnTableRows, err = findConnectedArtAndSearchViaArt(ctx, gqlclient, opts)
if err != nil {
logger.Fatalf("error finding artifact connected to package and searching via artifact: %v", err)
Expand Down Expand Up @@ -210,14 +210,17 @@ func findConnectedArtAndSearchViaArt(ctx context.Context, gqlclient graphql.Clie
return nil, nil, fmt.Errorf("error getting occurrences for package: %v", err)
}

art := occ.IsOccurrence[0].Artifact
if len(occ.IsOccurrence) > 0 {
art := occ.IsOccurrence[0].Artifact

newSearchString := art.Algorithm + ":" + art.Digest
newSearchString := art.Algorithm + ":" + art.Digest

depVulnPaths, depVulnTableRows, err = guacanalytics.SearchForSBOMViaArtifact(ctx, gqlclient, newSearchString, opts.depth)
if err != nil {
return nil, nil, fmt.Errorf("error searching via hasSBOM for artifact: %v", err)
depVulnPaths, depVulnTableRows, err = guacanalytics.SearchForSBOMViaArtifact(ctx, gqlclient, newSearchString, opts.depth)
if err != nil {
return nil, nil, fmt.Errorf("error searching via hasSBOM for artifact: %v", err)
}
}

return depVulnPaths, depVulnTableRows, nil
}

Expand Down
23 changes: 14 additions & 9 deletions pkg/guacanalytics/searchForSBOM.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ func SearchForSBOMViaPkg(ctx context.Context, gqlclient graphql.Client, searchSt
var tableRows []table.Row
checkedPkgIDs := make(map[string]bool)
var collectedPkgVersionResults []*pkgVersionNeighborQueryResults
AlreadyIncludedTableRows := make(map[string]bool)

queue := make([]string, 0) // the queue of nodes in bfs
type dfsNode struct {
Expand Down Expand Up @@ -354,16 +355,20 @@ func SearchForSBOMViaPkg(ctx context.Context, gqlclient graphql.Client, searchSt
if certifyVuln, ok := neighbor.(*model.NeighborsNeighborsCertifyVuln); ok {
if !checkedCertifyVulnIDs[certifyVuln.Id] && certifyVuln.Vulnerability.Type != noVulnType {
checkedCertifyVulnIDs[certifyVuln.Id] = true
for _, vuln := range certifyVuln.Vulnerability.VulnerabilityIDs {
tableRows = append(tableRows, table.Row{certifyVulnStr, certifyVuln.Id, "vulnerability ID: " + vuln.VulnerabilityID})
path = append(path, []string{vuln.Id, certifyVuln.Id,
certifyVuln.Package.Namespaces[0].Names[0].Versions[0].Id,
certifyVuln.Package.Namespaces[0].Names[0].Id, certifyVuln.Package.Namespaces[0].Id,
certifyVuln.Package.Id}...)
if !AlreadyIncludedTableRows[certifyVuln.Vulnerability.VulnerabilityIDs[0].VulnerabilityID] {
for _, vuln := range certifyVuln.Vulnerability.VulnerabilityIDs {
tableRows = append(tableRows, table.Row{certifyVulnStr, certifyVuln.Id, "vulnerability ID: " + vuln.VulnerabilityID})
path = append(path, []string{vuln.Id, certifyVuln.Id,
certifyVuln.Package.Namespaces[0].Names[0].Versions[0].Id,
certifyVuln.Package.Namespaces[0].Names[0].Id, certifyVuln.Package.Namespaces[0].Id,
certifyVuln.Package.Id}...)
}
path = append(path, result.isDep.Id, result.isDep.Package.Namespaces[0].Names[0].Versions[0].Id,
result.isDep.Package.Namespaces[0].Names[0].Id, result.isDep.Package.Namespaces[0].Id,
result.isDep.Package.Id)

AlreadyIncludedTableRows[certifyVuln.Vulnerability.VulnerabilityIDs[0].VulnerabilityID] = true
}
path = append(path, result.isDep.Id, result.isDep.Package.Namespaces[0].Names[0].Versions[0].Id,
result.isDep.Package.Namespaces[0].Names[0].Id, result.isDep.Package.Namespaces[0].Id,
result.isDep.Package.Id)
}
}

Expand Down

0 comments on commit 52c423f

Please sign in to comment.