aya: obj: implement sane defaults for license and kernel version

Default to license=GPL and kernel_version=any
pull/1/head
Alessandro Decina 4 years ago
parent f11df77f85
commit 1e779c520a

@ -93,15 +93,17 @@ impl Object {
let obj = object::read::File::parse(data).map_err(|e| ParseError::ElfError(e))?; let obj = object::read::File::parse(data).map_err(|e| ParseError::ElfError(e))?;
let endianness = obj.endianness(); let endianness = obj.endianness();
let section = obj let license = if let Some(section) = obj.section_by_name("license") {
.section_by_name("license") parse_license(Section::try_from(&section)?.data)?
.ok_or(ParseError::MissingLicense)?; } else {
let license = parse_license(Section::try_from(&section)?.data)?; CString::new("GPL").unwrap()
};
let section = obj let kernel_version = if let Some(section) = obj.section_by_name("version") {
.section_by_name("version") parse_version(Section::try_from(&section)?.data, endianness)?
.ok_or(ParseError::MissingKernelVersion)?; } else {
let kernel_version = parse_version(Section::try_from(&section)?.data, endianness)?; KernelVersion::Any
};
let mut bpf_obj = Object::new(endianness, license, kernel_version); let mut bpf_obj = Object::new(endianness, license, kernel_version);
@ -215,18 +217,12 @@ pub enum ParseError {
#[error("error parsing ELF data")] #[error("error parsing ELF data")]
ElfError(#[from] object::read::Error), ElfError(#[from] object::read::Error),
#[error("no license specified")]
MissingLicense,
#[error("invalid license `{data:?}`: missing NULL terminator")] #[error("invalid license `{data:?}`: missing NULL terminator")]
MissingLicenseNullTerminator { data: Vec<u8> }, MissingLicenseNullTerminator { data: Vec<u8> },
#[error("invalid license `{data:?}`")] #[error("invalid license `{data:?}`")]
InvalidLicense { data: Vec<u8> }, InvalidLicense { data: Vec<u8> },
#[error("missing kernel version")]
MissingKernelVersion,
#[error("invalid kernel version `{data:?}`")] #[error("invalid kernel version `{data:?}`")]
InvalidKernelVersion { data: Vec<u8> }, InvalidKernelVersion { data: Vec<u8> },

Loading…
Cancel
Save