do not attempt to load a BTF object that has no types

pull/608/head
Andrés Medina 2 years ago
parent 217e18ef93
commit 08e993dde3

@ -210,6 +210,11 @@ impl Btf {
} }
} }
pub(crate) fn is_empty(&self) -> bool {
// the first one is awlays BtfType::Unknown
self.types.types.len() < 2
}
pub(crate) fn types(&self) -> impl Iterator<Item = &BtfType> { pub(crate) fn types(&self) -> impl Iterator<Item = &BtfType> {
self.types.types.iter() self.types.types.iter()
} }
@ -628,7 +633,10 @@ impl Object {
&mut self, &mut self,
features: &BtfFeatures, features: &BtfFeatures,
) -> Result<Option<&Btf>, BtfError> { ) -> Result<Option<&Btf>, BtfError> {
if let Some(ref mut obj_btf) = self.btf { if let Some(ref mut obj_btf) = &mut self.btf {
if obj_btf.is_empty() {
return Ok(None);
}
// fixup btf // fixup btf
obj_btf.fixup_and_sanitize( obj_btf.fixup_and_sanitize(
&self.section_sizes, &self.section_sizes,

Loading…
Cancel
Save