Skip to content

Commit

Permalink
quic: Fix potential pointer alignmnet issue in adjustNewConnectionIdF…
Browse files Browse the repository at this point in the history
…orRouting (envoyproxy#30670)

Casting old_connection_id_ptr to a uint32_t is not safe because there is no guarantee that old_connection_id_ptr is 32 bit aligned. Instead, just call memcpy() explicitly with the size of 4.

Risk Level: Low
Testing: Existing
Docs Changes: N/A
Release Notes: N/A
Platform Specific Features: N/A

Signed-off-by: Ryan Hamilton <[email protected]>
  • Loading branch information
RyanTheOptimist authored Nov 2, 2023
1 parent 7d5f796 commit 8950270
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions source/common/quic/envoy_quic_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,8 @@ void adjustNewConnectionIdForRouting(quic::QuicConnectionId& new_connection_id,
const quic::QuicConnectionId& old_connection_id) {
char* new_connection_id_data = new_connection_id.mutable_data();
const char* old_connection_id_ptr = old_connection_id.data();
auto* first_four_bytes = reinterpret_cast<const uint32_t*>(old_connection_id_ptr);
// Override the first 4 bytes of the new CID to the original CID's first 4 bytes.
safeMemcpyUnsafeDst(new_connection_id_data, first_four_bytes);
memcpy(new_connection_id_data, old_connection_id_ptr, 4); // NOLINT(safe-memcpy)
}

} // namespace Quic
Expand Down

0 comments on commit 8950270

Please sign in to comment.