Skip to content
Closed
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
4 changes: 2 additions & 2 deletions vulnfeeds/conversion/versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -653,8 +653,8 @@ func processExtractedVersion(version string) string {
}

var (
textRangePattern = regexp.MustCompile(`(?i)(?:([vV]?[0-9][\w.+\-]*)\s+)?(through|before|prior\s+to|earlier\s+than|up\s+to(?:\s+and\s+including)?|fixed\s+in|patched\s+in|resolved\s+in|versions?\s*<=?)\s+(?:versions?\s+)?[vV]?([0-9][\w.+\-]*)`)
textTrailingInclusivePattern = regexp.MustCompile(`(?i)\b[vV]?([0-9]+(?:\.[0-9a-zA-Z.+\-]+)+)\s+and\s+(?:earlier|before|below|prior|older)\b`)
textRangePattern = regexp.MustCompile(`(?i)(?:([vV]?[0-9][\w.+\-]*)\s+)?(through|before|prior\s+to|earlier\s+than|up\s+to(?:\s+and\s+including)?|fixed\s+in|patched\s+in|resolved\s+in|versions?\s*<=?|below)\s+(?:versions?\s+)?[vV]?([0-9][\w.+\-]*)`)
textTrailingInclusivePattern = regexp.MustCompile(`(?i)\b[vV]?([0-9]+(?:\.[0-9a-zA-Z.+\-]+)+)\s+(?:and|or)\s+(?:earlier|before|below|prior|older)\b`)
textBeforeCommitPattern = regexp.MustCompile(`(?i)\b(?:before|prior\s+to|fixed\s+in)\s+commits?\s+([0-9a-f]{7,40})\b`)
textThroughCommitPattern = regexp.MustCompile(`(?i)\b(?:through|up\s+to|at|in)\s+commits?\s+([0-9a-f]{7,40})\b`)
textVulnerableCommitPattern = regexp.MustCompile(`(?i)\b([0-9a-f]{7,40})\s+(?:is\s+vulnerable|l?contains\s+a\b|has\s+a\b)`)
Expand Down
53 changes: 53 additions & 0 deletions vulnfeeds/conversion/versions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1844,6 +1844,41 @@ func TestExtractVersionsFromText(t *testing.T) {
wantLastAff: "77f55c4b466e99327c24ace8a2913d3ba7e2ccd5",
wantRangeTyp: "GIT",
},
{
name: "leading below version",
text: "An issue was discovered in FooBar below version 2.0.0 that allows a remote attacker to execute arbitrary code.",
wantIntro: "0",
wantFixed: "2.0.0",
wantRangeTyp: "UNSPECIFIED",
},
{
name: "leading below version without version keyword",
text: "A denial of service vulnerability exists in FooBar below 1.9.4.",
wantIntro: "0",
wantFixed: "1.9.4",
wantRangeTyp: "UNSPECIFIED",
},
{
name: "trailing or older",
text: "FooBar 1.2.3 or older contains a buffer overflow vulnerability.",
wantIntro: "0",
wantLastAff: "1.2.3",
wantRangeTyp: "UNSPECIFIED",
},
{
name: "trailing or earlier",
text: "FooBar 2.5.1 or earlier allows an attacker to bypass authentication.",
wantIntro: "0",
wantLastAff: "2.5.1",
wantRangeTyp: "UNSPECIFIED",
},
{
name: "trailing or below",
text: "FooBar 3.1.0 or below is vulnerable to cross-site scripting.",
wantIntro: "0",
wantLastAff: "3.1.0",
wantRangeTyp: "UNSPECIFIED",
},
}

for _, tc := range tests {
Expand Down Expand Up @@ -1873,3 +1908,21 @@ func TestExtractVersionsFromText(t *testing.T) {
})
}
}

func TestExtractVersionsFromText_NoVersionPhrase(t *testing.T) {
texts := []string{
"See below for the full list of affected products.",
"The fix is described below in the release notes.",
"Versions 1.0 and 2.0 are both supported.",
"This affects 1.2.3 or newer releases.",
}

for _, text := range texts {
t.Run(text, func(t *testing.T) {
metrics := &models.ConversionMetrics{}
if got := ExtractVersionsFromText(nil, text, metrics, models.VersionSourceDescription); len(got) != 0 {
t.Errorf("ExtractVersionsFromText(%q) returned ranges %+v, want none", text, got)
}
})
}
}