Skip to content

Commit 5ae53b8

Browse files
committed
cpe: fix handling of unset attributes when matching
This was an oversight on my part, missing a comment in the pseudocode that specifies this behavior. Signed-off-by: Hank Donnay <hdonnay@redhat.com>
1 parent 9bb03a1 commit 5ae53b8

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

toolkit/types/cpe/match.go

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77
// Compare implements the pairwise CPE comparison algorithm as defined by
88
// the CPE Name Matching spec: https://nvlpubs.nist.gov/nistpubs/Legacy/IR/nistir7696.pdf
99
func Compare(src, tgt WFN) Relations {
10+
// Per Section 5.4.2 of the CPE Naming specification, "any" and "unset" are
11+
// equivalent when reading from a WFN.
1012
var m [NumAttr]Relation
1113
for i := 0; i < NumAttr; i++ {
1214
sv, tv := src.Attr[i], tgt.Attr[i]
@@ -16,9 +18,9 @@ func Compare(src, tgt WFN) Relations {
1618
continue
1719
}
1820
switch sv.Kind {
19-
case ValueAny:
21+
case ValueAny, ValueUnset:
2022
switch tv.Kind {
21-
case ValueAny:
23+
case ValueAny, ValueUnset:
2224
m[i] = Equal
2325
case ValueNA:
2426
m[i] = Superset
@@ -27,7 +29,7 @@ func Compare(src, tgt WFN) Relations {
2729
}
2830
case ValueNA:
2931
switch tv.Kind {
30-
case ValueAny:
32+
case ValueAny, ValueUnset:
3133
m[i] = Subset
3234
case ValueNA:
3335
m[i] = Equal
@@ -37,7 +39,7 @@ func Compare(src, tgt WFN) Relations {
3739
case ValueSet:
3840
if hasWildcard(sv.V) {
3941
switch tv.Kind {
40-
case ValueAny:
42+
case ValueAny, ValueUnset:
4143
m[i] = Subset
4244
case ValueNA:
4345
m[i] = Disjoint
@@ -51,7 +53,7 @@ func Compare(src, tgt WFN) Relations {
5153
break
5254
}
5355
switch tv.Kind {
54-
case ValueAny:
56+
case ValueAny, ValueUnset:
5557
m[i] = Subset
5658
case ValueNA:
5759
m[i] = Disjoint
@@ -62,12 +64,6 @@ func Compare(src, tgt WFN) Relations {
6264
}
6365
m[i] = Disjoint
6466
}
65-
case ValueUnset:
66-
if tv.Kind == ValueUnset {
67-
m[i] = Equal
68-
break
69-
}
70-
m[i] = Disjoint
7167
}
7268
}
7369
return m

0 commit comments

Comments
 (0)