From 04d64c3e0fe60a25b1f1a5c2eaf7e2986d2130dd Mon Sep 17 00:00:00 2001 From: Jack Lloyd Date: Tue, 3 Oct 2017 00:38:15 -0400 Subject: Add wrappers for reinterpret_cast between char* and uint8_t* Generally speaking reinterpret_cast is sketchy stuff. But the special case of char*/uint8_t* is both common and safe. By isolating those, the remaining (likely sketchy) cases are easier to grep for. --- src/lib/tls/tls_channel.cpp | 2 +- src/lib/tls/tls_extensions.cpp | 8 +++----- src/lib/tls/tls_reader.h | 4 ++-- 3 files changed, 6 insertions(+), 8 deletions(-) (limited to 'src/lib/tls') diff --git a/src/lib/tls/tls_channel.cpp b/src/lib/tls/tls_channel.cpp index 034976ec4..78f681765 100644 --- a/src/lib/tls/tls_channel.cpp +++ b/src/lib/tls/tls_channel.cpp @@ -548,7 +548,7 @@ void Channel::send(const uint8_t buf[], size_t buf_size) void Channel::send(const std::string& string) { - this->send(reinterpret_cast(string.c_str()), string.size()); + this->send(cast_char_ptr_to_uint8(string.data()), string.size()); } void Channel::send_alert(const Alert& alert) diff --git a/src/lib/tls/tls_extensions.cpp b/src/lib/tls/tls_extensions.cpp index c76128632..317d96b8d 100644 --- a/src/lib/tls/tls_extensions.cpp +++ b/src/lib/tls/tls_extensions.cpp @@ -178,7 +178,7 @@ std::vector Server_Name_Indicator::serialize() const buf.push_back(get_byte(1, static_cast(name_len))); buf += std::make_pair( - reinterpret_cast(m_sni_host_name.data()), + cast_char_ptr_to_uint8(m_sni_host_name.data()), m_sni_host_name.size()); return buf; @@ -197,9 +197,7 @@ std::vector SRP_Identifier::serialize() const { std::vector buf; - const uint8_t* srp_bytes = - reinterpret_cast(m_srp_identifier.data()); - + const uint8_t* srp_bytes = cast_char_ptr_to_uint8(m_srp_identifier.data()); append_tls_length_value(buf, srp_bytes, m_srp_identifier.size(), 1); return buf; @@ -266,7 +264,7 @@ std::vector Application_Layer_Protocol_Notification::serialize() const throw TLS_Exception(Alert::INTERNAL_ERROR, "ALPN name too long"); if(p != "") append_tls_length_value(buf, - reinterpret_cast(p.data()), + cast_char_ptr_to_uint8(p.data()), p.size(), 1); } diff --git a/src/lib/tls/tls_reader.h b/src/lib/tls/tls_reader.h index 588335144..8474f1308 100644 --- a/src/lib/tls/tls_reader.h +++ b/src/lib/tls/tls_reader.h @@ -119,7 +119,7 @@ class TLS_Data_Reader final std::vector v = get_range_vector(len_bytes, min_bytes, max_bytes); - return std::string(reinterpret_cast(v.data()), v.size()); + return std::string(cast_uint8_ptr_to_char(v.data()), v.size()); } template @@ -219,7 +219,7 @@ void append_tls_length_value(std::vector& buf, size_t tag_size) { append_tls_length_value(buf, - reinterpret_cast(str.data()), + cast_char_ptr_to_uint8(str.data()), str.size(), tag_size); } -- cgit v1.2.3