Skip to content

Commit

Permalink
added panic recovery to software mutations flow just to be safe (#26932)
Browse files Browse the repository at this point in the history
> For #24784

# Checklist for submitter

If some of the following don't apply, delete the relevant line.

<!-- Note that API documentation changes are now addressed by the
product design team. -->
- [x] Added/updated automated tests
- [x] Manual QA for all new/changed functionality
  • Loading branch information
jahzielv authored Mar 7, 2025
1 parent eb60208 commit 32c5c47
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions server/vulnerabilities/nvd/cpe.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,11 @@ var (
func mutateSoftware(software *fleet.Software, logger log.Logger) {
for _, transformer := range softwareTransformers {
if transformer.matches(software) {
defer func() {
if r := recover(); r != nil {
level.Warn(logger).Log("msg", "panic during software mutation", "softwareName", software.Name, "softwareVersion", software.Version, "error", r)
}
}()
transformer.mutate(software, logger)
break
}
Expand Down
2 changes: 1 addition & 1 deletion server/vulnerabilities/nvd/cpe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2134,7 +2134,7 @@ func TestMutateSoftware(t *testing.T) {
},
} {
t.Run(tc.name, func(t *testing.T) {
mutateSoftware(tc.s, log.NewNopLogger())
require.NotPanics(t, func() { mutateSoftware(tc.s, log.NewNopLogger()) })
require.Equal(t, tc.sanitized, tc.s)
})
}
Expand Down

0 comments on commit 32c5c47

Please sign in to comment.