Merge pull request #171 from dave-tucker/nametoolong

aya: Truncate long program names
pull/172/head
Alessandro Decina 3 years ago committed by GitHub
commit dccdc45ccd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -201,13 +201,6 @@ pub enum ProgramError {
/// program name /// program name
name: String, name: String,
}, },
/// The program is too long.
#[error("the program name `{name}` iss longer than 16 characters")]
NameTooLong {
/// program name
name: String,
},
} }
/// Allows the Fd of a loaded [`Program`] to be retrieved /// Allows the Fd of a loaded [`Program`] to be retrieved
@ -424,13 +417,12 @@ fn load_program(prog_type: bpf_prog_type, data: &mut ProgramData) -> Result<(),
let mut ret; let mut ret;
let prog_name = if let Some(name) = &data.name { let prog_name = if let Some(name) = &data.name {
let name = name.clone(); let mut name = name.clone();
if name.len() > 16 {
name.truncate(16);
}
let prog_name = CString::new(name.clone()) let prog_name = CString::new(name.clone())
.map_err(|_| ProgramError::InvalidName { name: name.clone() })?; .map_err(|_| ProgramError::InvalidName { name: name.clone() })?;
if prog_name.to_bytes().len() > 16 {
return Err(ProgramError::NameTooLong { name });
}
Some(prog_name) Some(prog_name)
} else { } else {
None None

Loading…
Cancel
Save