diff --git a/rosenpass/src/api/boilerplate/message_type.rs b/rosenpass/src/api/boilerplate/message_type.rs index 8fca792..3a69564 100644 --- a/rosenpass/src/api/boilerplate/message_type.rs +++ b/rosenpass/src/api/boilerplate/message_type.rs @@ -6,6 +6,7 @@ use crate::RosenpassError::{self, InvalidApiMessageType}; pub type RawMsgType = u128; +// constants generated by gen-ipc-msg-types: // hash domain hash of: Rosenpass IPC API -> Rosenpass Protocol Server -> Ping Request pub const PING_REQUEST: RawMsgType = RawMsgType::from_le_bytes(hex!("2397 3ecc c441 704d 0b02 ea31 45d3 4999")); @@ -46,7 +47,7 @@ impl MessageAttributes for ResponseMsgType { impl TryFrom for RequestMsgType { type Error = RosenpassError; - fn try_from(value: u128) -> Result { + fn try_from(value: RawMsgType) -> Result { use RequestMsgType as E; Ok(match value { self::PING_REQUEST => E::Ping, @@ -67,7 +68,7 @@ impl From for RawMsgType { impl TryFrom for ResponseMsgType { type Error = RosenpassError; - fn try_from(value: u128) -> Result { + fn try_from(value: RawMsgType) -> Result { use ResponseMsgType as E; Ok(match value { self::PING_RESPONSE => E::Ping, diff --git a/rosenpass/src/api/cli.rs b/rosenpass/src/api/cli.rs index b160a5c..6c45c89 100644 --- a/rosenpass/src/api/cli.rs +++ b/rosenpass/src/api/cli.rs @@ -10,7 +10,7 @@ use super::config::ApiConfig; #[derive(Args, Debug)] pub struct ApiCli { /// Where in the file-system to create the unix socket the rosenpass API will be listening for - /// connections on + /// connections on. #[arg(long)] api_listen_path: Vec, diff --git a/rosenpass/src/api/mio/manager.rs b/rosenpass/src/api/mio/manager.rs index 172addf..c1ed019 100644 --- a/rosenpass/src/api/mio/manager.rs +++ b/rosenpass/src/api/mio/manager.rs @@ -70,6 +70,8 @@ impl MioManager { token_dispenser: &mut MioTokenDispenser, ) -> io::Result<()> { // Accept connection until the socket would block or returns another error + // TODO: This currently only adds connections--we eventually need the ability to remove + // them as well, see the note in connection.rs loop { match nonblocking_handle_io_errors(|| self.listeners[idx].accept())? { None => break, diff --git a/util/src/fd.rs b/util/src/fd.rs index 0268fa3..95ff08e 100644 --- a/util/src/fd.rs +++ b/util/src/fd.rs @@ -17,6 +17,8 @@ pub fn claim_fd(fd: RawFd) -> rustix::io::Result { } pub fn mask_fd(fd: RawFd) -> rustix::io::Result<()> { + // Safety: because the OwnedFd resulting from OwnedFd::from_raw_fd is wrapped in a Forgetting, + // it never gets dropped, meaning that fd is never closed and thus outlives the OwnedFd let mut owned = Forgetting::new(unsafe { OwnedFd::from_raw_fd(fd) }); clone_fd_to_cloexec(open_nullfd()?, &mut owned) } diff --git a/util/src/length_prefix_encoding/decoder.rs b/util/src/length_prefix_encoding/decoder.rs index 26a7130..1769b70 100644 --- a/util/src/length_prefix_encoding/decoder.rs +++ b/util/src/length_prefix_encoding/decoder.rs @@ -19,7 +19,7 @@ pub enum SanityError { } #[derive(Error, Debug)] -#[error("Message too lage ({msg_size} bytes) for buffer ({buf_size} bytes)")] +#[error("Message too large ({msg_size} bytes) for buffer ({buf_size} bytes)")] pub struct MessageTooLargeError { msg_size: usize, buf_size: usize, @@ -132,7 +132,7 @@ impl> LengthPrefixDecoder { Ok(match self.next_slice_to_write_to()? { // Read some bytes; any MessageTooLargeError in the call to self.message_mut() is // ignored to ensure this function changes no state upon errors; the user should rerun - // the function and colect the MessageTooLargeError on the following invocation + // the function and collect the MessageTooLargeError on the following invocation Some(buf) => { let bytes_read = r.read(buf)?; self.advance(bytes_read).unwrap(); diff --git a/util/src/zerocopy/ref_maker.rs b/util/src/zerocopy/ref_maker.rs index 13e6fe9..0b18702 100644 --- a/util/src/zerocopy/ref_maker.rs +++ b/util/src/zerocopy/ref_maker.rs @@ -57,21 +57,22 @@ impl RefMaker { Ok(Self::from_prefix_with_tail(self)?.0) } - pub fn from_suffix_with_tail(self) -> anyhow::Result<(Self, B)> { + pub fn from_suffix_with_head(self) -> anyhow::Result<(Self, B)> { self.ensure_fit()?; let point = self.bytes().len() - Self::target_size(); let (head, tail) = self.buf.split_at(point); - Ok((Self::new(head), tail)) + Ok((Self::new(tail), head)) } pub fn split_suffix(self) -> anyhow::Result<(Self, Self)> { self.ensure_fit()?; - let (head, tail) = self.buf.split_at(Self::target_size()); + let point = self.bytes().len() - Self::target_size(); + let (head, tail) = self.buf.split_at(point); Ok((Self::new(head), Self::new(tail))) } pub fn from_suffix(self) -> anyhow::Result { - Ok(Self::from_suffix_with_tail(self)?.0) + Ok(Self::from_suffix_with_head(self)?.0) } pub fn bytes(&self) -> &[u8] { diff --git a/util/src/zerocopy/zerocopy_slice_ext.rs b/util/src/zerocopy/zerocopy_slice_ext.rs index eb0000a..1399253 100644 --- a/util/src/zerocopy/zerocopy_slice_ext.rs +++ b/util/src/zerocopy/zerocopy_slice_ext.rs @@ -16,7 +16,7 @@ pub trait ZerocopySliceExt: Sized + ByteSlice { } fn zk_parse_suffix(self) -> anyhow::Result> { - self.zk_ref_maker().from_prefix()?.parse() + self.zk_ref_maker().from_suffix()?.parse() } } @@ -31,8 +31,8 @@ pub trait ZerocopyMutSliceExt: ZerocopySliceExt + Sized + ByteSliceMut { self.zk_ref_maker().from_prefix()?.make_zeroized() } - fn zk_zeroized_from_suffic(self) -> anyhow::Result> { - self.zk_ref_maker().from_prefix()?.make_zeroized() + fn zk_zeroized_from_suffix(self) -> anyhow::Result> { + self.zk_ref_maker().from_suffix()?.make_zeroized() } }