Skip to content

Commit e45b79c

Browse files
committed
oval: handle unknown for date fields
The Ubuntu feed will surface "unknown" for dates i.e. <public_date>, this currently causes an error until the feed is fixed. This will use an effect zero date instead: time.Time{} 0001-01-01 00:00:00 +0000 UTC Signed-off-by: crozzy <[email protected]>
1 parent f743bb0 commit e45b79c

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

oval/date_test.go

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,29 @@ func TestUbuntuDates(t *testing.T) {
126126
}
127127
}
128128

129-
func TestPointlessElement(t *testing.T) {
130-
const doc = xml.Header + `<div><issued date=""/></div>`
129+
func TestBadDateElements(t *testing.T) {
131130
var got struct {
132131
Date Date `xml:"issued"`
133132
}
134133

135-
rd := strings.NewReader(doc)
136-
if err := xml.NewDecoder(rd).Decode(&got); err != nil {
137-
t.Error(err)
134+
tests := []struct {
135+
name string
136+
in string
137+
}{
138+
{
139+
name: "TestPointlessElement",
140+
in: `<div><issued date=""/></div>`,
141+
},
142+
{
143+
name: "TestUnknown",
144+
in: `<div><issued>unknown</issued></div>`,
145+
},
146+
}
147+
for _, test := range tests {
148+
doc := xml.Header + test.in
149+
rd := strings.NewReader(doc)
150+
if err := xml.NewDecoder(rd).Decode(&got); err != nil {
151+
t.Error(test.name, err)
152+
}
138153
}
139154
}

oval/types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ func (d *Date) UnmarshalXML(dec *xml.Decoder, start xml.StartElement) error {
149149
// pointless but we need to not return an error.
150150
d.Date = time.Time{}
151151
return nil
152+
case s == "unknown":
153+
// Ubuntu occasionally add vulnerability definitions with "unknown" in the date field.
154+
d.Date = time.Time{}
155+
return nil
152156
case s == "" && !d.Date.IsZero():
153157
// If the date is set but an empty string is the inner element, then the
154158
// date was set by an attr.

0 commit comments

Comments
 (0)