From c064eda7e4671b9602a5a031ed8889c9984cca4a Mon Sep 17 00:00:00 2001 From: 5225225 <5225225@mailbox.org> Date: Tue, 12 Jul 2022 08:04:44 +0100 Subject: [PATCH 1/3] fix(http1): fix invalid use of mem::uninit In newer versions of rust, mem::uninitialized and mem::zeroed will panic when they are used for types that don't allow it in more cases. This change allows the tests to run successfully even with the strictest form of the checks. --- Cargo.toml | 4 ++-- src/proto/h1/role.rs | 19 +++++++------------ 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ac1141b3ee..df194c90ec 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,7 +29,7 @@ http-body = "0.3.1" httpdate = "0.3" httparse = "1.0" h2 = "0.2.2" -itoa = "0.4.1" +itoa = "1" tracing = { version = "0.1", default-features = false, features = ["log", "std"] } pin-project = "1.0" tower-service = "0.3" @@ -56,7 +56,7 @@ tower-util = "0.3" url = "1.0" [target.'cfg(any(target_os = "linux", target_os = "macos"))'.dev-dependencies] -pnet = "0.25.0" +pnet = "0.29.0" [features] default = [ diff --git a/src/proto/h1/role.rs b/src/proto/h1/role.rs index ca8e52c30d..9c8759d28e 100644 --- a/src/proto/h1/role.rs +++ b/src/proto/h1/role.rs @@ -111,13 +111,9 @@ impl Http1Transaction for Server { let len; let headers_len; - // Unsafe: both headers_indices and headers are using uninitialized memory, - // but we *never* read any of it until after httparse has assigned - // values into it. By not zeroing out the stack memory, this saves - // a good ~5% on pipeline benchmarks. - let mut headers_indices: [HeaderIndices; MAX_HEADERS] = unsafe { mem::uninitialized() }; + let mut headers_indices: [HeaderIndices; MAX_HEADERS] = unsafe { mem::zeroed() }; { - let mut headers: [httparse::Header<'_>; MAX_HEADERS] = unsafe { mem::uninitialized() }; + let mut headers = [httparse::EMPTY_HEADER; MAX_HEADERS]; trace!( "Request.parse([Header; {}], [u8; {}])", headers.len(), @@ -276,7 +272,7 @@ impl Http1Transaction for Server { fn encode( mut msg: Encode<'_, Self::Outgoing>, - mut dst: &mut Vec, + dst: &mut Vec, ) -> crate::Result { trace!( "Server::encode status={:?}, body={:?}, req_method={:?}", @@ -562,7 +558,8 @@ impl Http1Transaction for Server { Encoder::length(0) } else { extend(dst, b"content-length: "); - let _ = ::itoa::write(&mut dst, len); + let mut buf = itoa::Buffer::new(); + extend(dst, buf.format(len).as_bytes()); extend(dst, b"\r\n"); Encoder::length(len) } @@ -650,11 +647,9 @@ impl Http1Transaction for Client { // Loop to skip information status code headers (100 Continue, etc). loop { - // Unsafe: see comment in Server Http1Transaction, above. - let mut headers_indices: [HeaderIndices; MAX_HEADERS] = unsafe { mem::uninitialized() }; + let mut headers_indices: [HeaderIndices; MAX_HEADERS] = unsafe { mem::zeroed() }; let (len, status, version, headers_len) = { - let mut headers: [httparse::Header<'_>; MAX_HEADERS] = - unsafe { mem::uninitialized() }; + let mut headers = [httparse::EMPTY_HEADER; MAX_HEADERS]; trace!( "Response.parse([Header; {}], [u8; {}])", headers.len(), From c5faa37119033311752e67f8787a14ac9fb2a4f1 Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Wed, 12 May 2021 17:51:45 -0700 Subject: [PATCH 2/3] docs(common): remove favicon doc from sync_wrapper module (#2548) --- src/common/sync_wrapper.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/common/sync_wrapper.rs b/src/common/sync_wrapper.rs index 1e4aa4039c..aac9d4ee74 100644 --- a/src/common/sync_wrapper.rs +++ b/src/common/sync_wrapper.rs @@ -1,11 +1,6 @@ /* * This is a copy of the sync_wrapper crate. */ -//! A mutual exclusion primitive that relies on static type information only -//! -//! This library is inspired by [this discussion](https://internals.rust-lang.org/t/what-shall-sync-mean-across-an-await/12020/2). -#![doc(html_logo_url = "https://developer.actyx.com/img/logo.svg")] -#![doc(html_favicon_url = "https://developer.actyx.com/img/favicon.ico")] /// A mutual exclusion primitive that relies on static type information only /// From 2a77117603f561040ef15e4be2ff474f4ca050e8 Mon Sep 17 00:00:00 2001 From: 5225225 <5225225@mailbox.org> Date: Thu, 14 Jul 2022 17:07:50 +0100 Subject: [PATCH 3/3] style: ignore drained_tx unused warning --- src/common/drain.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/common/drain.rs b/src/common/drain.rs index 7abb9f9ded..97c976fdd3 100644 --- a/src/common/drain.rs +++ b/src/common/drain.rs @@ -35,6 +35,8 @@ pub struct Draining { } #[derive(Clone)] +// drained_tx is never ready +#[allow(dead_code)] pub struct Watch { drained_tx: mpsc::Sender, rx: watch::Receiver,