Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion cli/gitcommands.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ func GitAuditCmd(c *components.Context) error {
gitAuditCmd.SetUploadCdxResults(uploadResults).SetRtResultRepository(c.GetStringFlagValue(flags.UploadRtRepoPath))
// Run the command with progress bar if needed, Reporting error if Xsc service is enabled
err = reportErrorIfExists(xrayVersion, xscVersion, serverDetails, gitAuditCmd.GetProjectKey(), progressbar.ExecWithProgress(gitAuditCmd))
log.Info("####### jf git audit Scan Finished #######")
return err
}

Expand Down
1 change: 0 additions & 1 deletion cli/scancommands.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,6 @@ func AuditCmd(c *components.Context) error {
auditCmd.SetThreads(threads)
// Reporting error if Xsc service is enabled
err = reportErrorIfExists(xrayVersion, xscVersion, serverDetails, auditCmd.GetProjectKey(), progressbar.ExecWithProgress(auditCmd))
log.Info("####### jf audit Scan Finished #######")
return err
}

Expand Down
2 changes: 1 addition & 1 deletion commands/audit/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ func (auditCmd *AuditCommand) Run() (err error) {
return errors.Join(err, auditResults.GetErrors())
}
}

log.Info("####### jf audit Scan Finished #######")
return OutputResultsAndCmdError(auditResults, auditCmd.getResultWriter(auditResults), auditCmd.Fail)
}

Expand Down
1 change: 1 addition & 0 deletions commands/git/audit/gitaudit.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func (gaCmd *GitAuditCommand) Run() (err error) {
return errors.Join(err, auditResults.GetErrors())
}
}
log.Info("####### jf git audit Scan Finished #######")
return sourceAudit.OutputResultsAndCmdError(auditResults, gaCmd.getResultWriter(auditResults), gaCmd.failBuild)
}

Expand Down
18 changes: 13 additions & 5 deletions utils/results/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ const (
DirectDependencyPathLength = 2
nodeModules = "node_modules"

// MaxUniqueAppearances defines the maximum number of times a dependency can appear in a dependency tree.
MaxUniqueAppearances = 10

// <FILE_REF>#L<START_LINE>C<START_COLUMN>-L<END_LINE>C<END_COLUMN>
LocationIdTemplate = "%s#L%dC%d-L%dC%d"
// Applicability properties for cdx
Expand Down Expand Up @@ -1024,10 +1027,11 @@ func BomToFullTree(sbom *cyclonedx.BOM, convertToXrayCompId bool) (fullDependenc
// No dependencies or components in the SBOM, return an empty slice
return
}
dependencyAppearances := map[string]int8{}
for _, rootEntry := range cdxutils.GetRootDependenciesEntries(sbom, false) {
// Create a new GraphNode with ref as the ID, when populating the tree we need to use the ref as the ID
currentTree := &xrayUtils.GraphNode{Id: rootEntry.Ref}
populateDepsNodeDataFromBom(currentTree, sbom.Dependencies)
populateDepsNodeDataFromBom(currentTree, sbom.Dependencies, dependencyAppearances)
fullDependencyTrees = append(fullDependencyTrees, currentTree)
}
// Translate refs to Purl/Xray IDs
Expand All @@ -1037,17 +1041,21 @@ func BomToFullTree(sbom *cyclonedx.BOM, convertToXrayCompId bool) (fullDependenc
return
}

func populateDepsNodeDataFromBom(node *xrayUtils.GraphNode, dependencies *[]cyclonedx.Dependency) {
if node == nil || node.NodeHasLoop() {
// If the node is nil or has a loop, return
func populateDepsNodeDataFromBom(node *xrayUtils.GraphNode, dependencies *[]cyclonedx.Dependency, dependencyAppearances map[string]int8) {
if node == nil {
return
}
dependencyAppearances[node.Id]++
if dependencyAppearances[node.Id] >= MaxUniqueAppearances || node.NodeHasLoop() {
// If the node has a loop or appeared too many times, stop the recursion
return
}
for _, dep := range cdxutils.GetDirectDependencies(dependencies, node.Id) {
depNode := &xrayUtils.GraphNode{Id: dep, Parent: node}
// Add the dependency to the current node
node.Nodes = append(node.Nodes, depNode)
// Recursively populate the node data
populateDepsNodeDataFromBom(depNode, dependencies)
populateDepsNodeDataFromBom(depNode, dependencies, dependencyAppearances)
}
}

Expand Down
Loading