From 6305b2302932f2db091d5bddc11df49f761a1e93 Mon Sep 17 00:00:00 2001 From: Jake Shadle Date: Fri, 9 Aug 2024 10:50:20 +0200 Subject: [PATCH] Add missing SAFETY docs --- src/components/proxy/io_uring_shared.rs | 2 ++ src/components/proxy/sessions/inner_metrics.rs | 1 + src/metrics.rs | 1 + src/pool.rs | 2 ++ 4 files changed, 6 insertions(+) diff --git a/src/components/proxy/io_uring_shared.rs b/src/components/proxy/io_uring_shared.rs index dad2f3bf6..179e38c47 100644 --- a/src/components/proxy/io_uring_shared.rs +++ b/src/components/proxy/io_uring_shared.rs @@ -465,6 +465,8 @@ impl<'uring> LoopCtx<'uring> { self.sq.sync(); match self.backlog.pop_front() { + // SAFETY: Same as Self::push, all memory pointed to in our ops are pinned at + // stable locations in memory Some(sqe) => unsafe { let _ = self.sq.push(&sqe); }, diff --git a/src/components/proxy/sessions/inner_metrics.rs b/src/components/proxy/sessions/inner_metrics.rs index 6ee30c0e2..bc2902ffa 100644 --- a/src/components/proxy/sessions/inner_metrics.rs +++ b/src/components/proxy/sessions/inner_metrics.rs @@ -41,6 +41,7 @@ pub(crate) fn active_sessions(asn: Option<&crate::net::maxmind_db::IpNetEntry>) let len = crate::metrics::itoa(asnfo.id, &mut asn); ACTIVE_SESSIONS.with_label_values(&[ + // SAFETY: itoa only writes ASCII unsafe { std::str::from_utf8_unchecked(&asn[..len as _]) }, &asnfo.as_name, &asnfo.as_cc, diff --git a/src/metrics.rs b/src/metrics.rs index e07a0369c..f5d9a9892 100644 --- a/src/metrics.rs +++ b/src/metrics.rs @@ -86,6 +86,7 @@ pub struct AsnInfo<'a> { impl<'a> AsnInfo<'a> { #[inline] fn asn_str(&self) -> &str { + // SAFETY: we only write ASCII in itoa unsafe { std::str::from_utf8_unchecked(&self.asn[..self.asn_len as _]) } } } diff --git a/src/pool.rs b/src/pool.rs index 261e5398b..d37bd995e 100644 --- a/src/pool.rs +++ b/src/pool.rs @@ -197,6 +197,8 @@ impl PoolBuffer { #[inline] #[cfg(target_os = "linux")] pub(crate) fn set_len(&mut self, len: usize) { + // SAFETY: len is the length as returned from the kernel on a successful + // recv_from call unsafe { self.inner.set_len(len) } } }