From 575fea4cb9a19540de82283855fb84fad8113dfd Mon Sep 17 00:00:00 2001 From: Ricky Han Date: Wed, 2 Nov 2022 06:58:10 +0000 Subject: [PATCH] fix wrong bounds --- aya/src/maps/array/array.rs | 2 +- aya/src/maps/hash_map/hash_map.rs | 2 +- aya/src/maps/hash_map/mod.rs | 4 ++-- aya/src/maps/lpm_trie.rs | 2 +- aya/src/maps/sock/sock_hash.rs | 2 +- aya/src/maps/stack.rs | 2 +- aya/src/sys/bpf.rs | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/aya/src/maps/array/array.rs b/aya/src/maps/array/array.rs index f38d992c..72b48668 100644 --- a/aya/src/maps/array/array.rs +++ b/aya/src/maps/array/array.rs @@ -89,7 +89,7 @@ impl, V: Pod> Array { /// /// Returns [`MapError::OutOfBounds`] if `index` is out of bounds, [`MapError::SyscallError`] /// if `bpf_map_update_elem` fails. - pub fn set(&mut self, index: u32, value: impl Borrow, flags: u64) -> Result<(), MapError> { + pub fn set(&mut self, index: u32, value: impl Borrow + Pod, flags: u64) -> Result<(), MapError> { let data = self.inner.as_mut(); check_bounds(data, index)?; let fd = data.fd_or_err()?; diff --git a/aya/src/maps/hash_map/hash_map.rs b/aya/src/maps/hash_map/hash_map.rs index 3745865e..e7045466 100644 --- a/aya/src/maps/hash_map/hash_map.rs +++ b/aya/src/maps/hash_map/hash_map.rs @@ -85,7 +85,7 @@ impl, K: Pod, V: Pod> HashMap { value: impl Borrow, flags: u64, ) -> Result<(), MapError> { - hash_map::insert(self.inner.as_mut(), &key, &value, flags) + hash_map::insert(self.inner.as_mut(), key.borrow(), value.borrow(), flags) } /// Removes a key from the map. diff --git a/aya/src/maps/hash_map/mod.rs b/aya/src/maps/hash_map/mod.rs index b272d23f..409a64b9 100644 --- a/aya/src/maps/hash_map/mod.rs +++ b/aya/src/maps/hash_map/mod.rs @@ -1,7 +1,7 @@ //! Hash map types. use crate::{ maps::MapError, - sys::{bpf_map_delete_elem, bpf_map_update_elem}, + sys::{bpf_map_delete_elem, bpf_map_update_elem}, Pod, }; #[allow(clippy::module_inception)] @@ -13,7 +13,7 @@ pub use per_cpu_hash_map::*; use super::MapData; -pub(crate) fn insert( +pub(crate) fn insert( map: &mut MapData, key: &K, value: &V, diff --git a/aya/src/maps/lpm_trie.rs b/aya/src/maps/lpm_trie.rs index 505fbc5d..e132cc01 100644 --- a/aya/src/maps/lpm_trie.rs +++ b/aya/src/maps/lpm_trie.rs @@ -136,7 +136,7 @@ impl, K: Pod, V: Pod> LpmTrie { flags: u64, ) -> Result<(), MapError> { let fd = self.inner.as_mut().fd_or_err()?; - bpf_map_update_elem(fd, Some(key), &value, flags).map_err(|(_, io_error)| { + bpf_map_update_elem(fd, Some(key), value.borrow(), flags).map_err(|(_, io_error)| { MapError::SyscallError { call: "bpf_map_update_elem".to_owned(), io_error, diff --git a/aya/src/maps/sock/sock_hash.rs b/aya/src/maps/sock/sock_hash.rs index 08366530..7da2d097 100644 --- a/aya/src/maps/sock/sock_hash.rs +++ b/aya/src/maps/sock/sock_hash.rs @@ -122,7 +122,7 @@ impl, K: Pod> SockHash { value: I, flags: u64, ) -> Result<(), MapError> { - hash_map::insert(self.inner.as_mut(), &key, &value.as_raw_fd(), flags) + hash_map::insert(self.inner.as_mut(), key.borrow(), &value.as_raw_fd(), flags) } /// Removes a socket from the map. diff --git a/aya/src/maps/stack.rs b/aya/src/maps/stack.rs index ff156c0e..c0742cfa 100644 --- a/aya/src/maps/stack.rs +++ b/aya/src/maps/stack.rs @@ -81,7 +81,7 @@ impl, V: Pod> Stack { /// [`MapError::SyscallError`] if `bpf_map_update_elem` fails. pub fn push(&mut self, value: impl Borrow, flags: u64) -> Result<(), MapError> { let fd = self.inner.as_mut().fd_or_err()?; - bpf_map_update_elem(fd, None::<&u32>, &value, flags).map_err(|(_, io_error)| { + bpf_map_update_elem(fd, None::<&u32>, value.borrow(), flags).map_err(|(_, io_error)| { MapError::SyscallError { call: "bpf_map_update_elem".to_owned(), io_error, diff --git a/aya/src/sys/bpf.rs b/aya/src/sys/bpf.rs index f408a49b..1791b05c 100644 --- a/aya/src/sys/bpf.rs +++ b/aya/src/sys/bpf.rs @@ -232,7 +232,7 @@ pub(crate) fn bpf_map_lookup_elem_ptr( } } -pub(crate) fn bpf_map_update_elem( +pub(crate) fn bpf_map_update_elem( fd: RawFd, key: Option<&K>, value: &V,