Skip to content

Commit 9437a24

Browse files
committed
feat(contrib/snmp2cpe): skip invalid CPE
1 parent ebfb0d5 commit 9437a24

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

contrib/snmp2cpe/pkg/cpe/cpe.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@ package cpe
22

33
import (
44
"fmt"
5+
"log"
6+
"maps"
7+
"slices"
58
"strings"
69

710
"github.com/hashicorp/go-version"
11+
"github.com/knqyf263/go-cpe/naming"
812

913
"github.com/future-architect/vuls/contrib/snmp2cpe/pkg/snmp"
10-
"github.com/future-architect/vuls/contrib/snmp2cpe/pkg/util"
1114
)
1215

1316
// Convert ...
@@ -424,7 +427,16 @@ func Convert(result snmp.Result) []string {
424427
return []string{}
425428
}
426429

427-
return util.Unique(cpes)
430+
m := make(map[string]struct{}, len(cpes))
431+
for _, c := range cpes {
432+
if _, err := naming.UnbindFS(c); err != nil {
433+
log.Printf("WARN: skip %q. err: %s", c, err)
434+
continue
435+
}
436+
m[c] = struct{}{}
437+
}
438+
439+
return slices.Collect(maps.Keys(m))
428440
}
429441

430442
func detectVendor(r snmp.Result) string {

contrib/snmp2cpe/pkg/util/util.go

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)