From 0a9d02140acdaa35c5f5c7e17ea08a6823922e20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alessandro=C2=A0Decina?= Date: Fri, 23 Jul 2021 06:40:57 +0000 Subject: [PATCH] aya: netlink: fix alignment when writing attributes --- aya/src/sys/netlink.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/aya/src/sys/netlink.rs b/aya/src/sys/netlink.rs index 033d58d7..36c508de 100644 --- a/aya/src/sys/netlink.rs +++ b/aya/src/sys/netlink.rs @@ -438,13 +438,15 @@ fn write_attr_header(buf: &mut [u8], offset: usize, attr: nlattr) -> Result Result { - if offset + value.len() > buf.len() { + let align_len = align_to(value.len(), NLA_ALIGNTO as usize); + if offset + align_len > buf.len() { return Err(io::Error::new(io::ErrorKind::Other, "no space left")); } buf[offset..offset + value.len()].copy_from_slice(value); - Ok(value.len()) + Ok(align_len) +} }