ovalutil: guard a test element with no object reference - #1976
Conversation
|
Thanks for the PR, curious; have you seen this in the wild? |
|
Honest answer: no, not from a production crash. I came at it from the other direction, reading the OVAL handling for places where a document shape that the spec permits is not one the code expects. The specific shape is a So treat it as hardening rather than a bug report, and if that is not worth the diff I am fine with it being closed. The branch is behind main now, so tell me either way and I will rebase if you want it. |
|
Ahh, no I think it's good to include, just sometimes we see these PRs and have no context for how people are using claircore to produce the error. I can also rebase. |
Both DefsToVulns loops read ObjectRef()[0] with no length check, while the StateRef() right below is guarded by len(stateRefs) > 0. The object reference is required by the OVAL schema but the parser does not enforce it, so a feed carrying an rpminfo_test or dpkginfo_test without an <object> child panics the updater with index out of range [0] with length 0 Skip the criterion instead, the same way an object lookup failure is already handled. Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
b43a5f9 to
45b34b7
Compare
|
That makes sense, and it is a fair thing to ask. I have rebased it onto main so you do not have to. For the record on how it turned up: I was reading the OVAL definitions schema for places where a document shape the spec permits is not one the code expects, rather than working back from a failure in a deployment. The specific shape is a
|
RPMDefsToVulnsandDpkgDefsToVulnsboth do this:and then, a few lines further down, guard the sibling with
if len(stateRefs) > 0. The comment above explains why the state reference is optional and the object reference is required, but "required by the schema" is not the same as "present in the document": goval-parser does not enforce it, so a test element with no<object>child parses fine and then indexes an empty slice.That happens while unpacking criterions during an update, so a single malformed test element in a fetched OVAL feed takes down the updater rather than costing one vulnerability.
Both call sites now skip the criterion, which is what already happens when the object lookup itself fails. rpm.go logs at debug like the lookup failures around it; dpkg.go increments the existing
stats.Objcounter, which is reported at the end of the run.TestDefsToVulnsWithoutObjectRefparses a minimal OVAL document with the object reference omitted and runs both entry points over it. On the unmodified tree the rpminfo case panics and takes the test binary with it; with this change both return no vulnerabilities and no error.go test ./pkg/ovalutil/passes.