Skip to content

ovalutil: guard a test element with no object reference - #1976

Open
arpitjain099 wants to merge 1 commit into
quay:mainfrom
arpitjain099:ovalutil/guard-missing-object-ref
Open

ovalutil: guard a test element with no object reference#1976
arpitjain099 wants to merge 1 commit into
quay:mainfrom
arpitjain099:ovalutil/guard-missing-object-ref

Conversation

@arpitjain099

Copy link
Copy Markdown
Contributor

RPMDefsToVulns and DpkgDefsToVulns both do this:

objRefs := test.ObjectRef()
stateRefs := test.StateRef()
...
objRef := objRefs[0].ObjectRef

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.

panic: runtime error: index out of range [0] with length 0

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.Obj counter, which is reported at the end of the run.

TestDefsToVulnsWithoutObjectRef parses 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.

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>
@arpitjain099
arpitjain099 requested review from a team as code owners August 3, 2026 02:17
@arpitjain099
arpitjain099 requested a review from crozzy August 3, 2026 02:17
@crozzy

crozzy commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Thanks for the PR, curious; have you seen this in the wild?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants