fix wrong bounds

pull/431/head
Ricky Han 2 years ago
parent fbfbedb6a8
commit 575fea4cb9

@ -89,7 +89,7 @@ impl<T: AsMut<MapData>, V: Pod> Array<T, V> {
/// ///
/// Returns [`MapError::OutOfBounds`] if `index` is out of bounds, [`MapError::SyscallError`] /// Returns [`MapError::OutOfBounds`] if `index` is out of bounds, [`MapError::SyscallError`]
/// if `bpf_map_update_elem` fails. /// if `bpf_map_update_elem` fails.
pub fn set(&mut self, index: u32, value: impl Borrow<V>, flags: u64) -> Result<(), MapError> { pub fn set(&mut self, index: u32, value: impl Borrow<V> + Pod, flags: u64) -> Result<(), MapError> {
let data = self.inner.as_mut(); let data = self.inner.as_mut();
check_bounds(data, index)?; check_bounds(data, index)?;
let fd = data.fd_or_err()?; let fd = data.fd_or_err()?;

@ -85,7 +85,7 @@ impl<T: AsMut<MapData>, K: Pod, V: Pod> HashMap<T, K, V> {
value: impl Borrow<V>, value: impl Borrow<V>,
flags: u64, flags: u64,
) -> Result<(), MapError> { ) -> 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. /// Removes a key from the map.

@ -1,7 +1,7 @@
//! Hash map types. //! Hash map types.
use crate::{ use crate::{
maps::MapError, 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)] #[allow(clippy::module_inception)]
@ -13,7 +13,7 @@ pub use per_cpu_hash_map::*;
use super::MapData; use super::MapData;
pub(crate) fn insert<K, V>( pub(crate) fn insert<K: Pod, V: Pod>(
map: &mut MapData, map: &mut MapData,
key: &K, key: &K,
value: &V, value: &V,

@ -136,7 +136,7 @@ impl<T: AsMut<MapData>, K: Pod, V: Pod> LpmTrie<T, K, V> {
flags: u64, flags: u64,
) -> Result<(), MapError> { ) -> Result<(), MapError> {
let fd = self.inner.as_mut().fd_or_err()?; 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 { MapError::SyscallError {
call: "bpf_map_update_elem".to_owned(), call: "bpf_map_update_elem".to_owned(),
io_error, io_error,

@ -122,7 +122,7 @@ impl<T: AsMut<MapData>, K: Pod> SockHash<T, K> {
value: I, value: I,
flags: u64, flags: u64,
) -> Result<(), MapError> { ) -> 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. /// Removes a socket from the map.

@ -81,7 +81,7 @@ impl<T: AsMut<MapData>, V: Pod> Stack<T, V> {
/// [`MapError::SyscallError`] if `bpf_map_update_elem` fails. /// [`MapError::SyscallError`] if `bpf_map_update_elem` fails.
pub fn push(&mut self, value: impl Borrow<V>, flags: u64) -> Result<(), MapError> { pub fn push(&mut self, value: impl Borrow<V>, flags: u64) -> Result<(), MapError> {
let fd = self.inner.as_mut().fd_or_err()?; 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 { MapError::SyscallError {
call: "bpf_map_update_elem".to_owned(), call: "bpf_map_update_elem".to_owned(),
io_error, io_error,

@ -232,7 +232,7 @@ pub(crate) fn bpf_map_lookup_elem_ptr<K: Pod, V>(
} }
} }
pub(crate) fn bpf_map_update_elem<K, V>( pub(crate) fn bpf_map_update_elem<K: Pod, V: Pod>(
fd: RawFd, fd: RawFd,
key: Option<&K>, key: Option<&K>,
value: &V, value: &V,

Loading…
Cancel
Save