From 07da15711f5aab124ed56fc449f9d550ab0fdccb Mon Sep 17 00:00:00 2001 From: klzgrad Date: Sat, 30 Nov 2019 22:19:02 +0800 Subject: [PATCH] crl_set: Support big endian --- src/net/cert/crl_set.cc | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/src/net/cert/crl_set.cc b/src/net/cert/crl_set.cc index 4f09e69fbd..38d3cae00c 100644 --- a/src/net/cert/crl_set.cc +++ b/src/net/cert/crl_set.cc @@ -46,8 +46,8 @@ base::DictionaryValue* ReadHeader(base::StringPiece* data) { uint16_t header_len; if (data->size() < sizeof(header_len)) return nullptr; - // Assumes little-endian. - memcpy(&header_len, data->data(), sizeof(header_len)); + header_len = static_cast(data->data()[0]); + header_len |= static_cast(data->data()[1]) << 8; data->remove_prefix(sizeof(header_len)); if (data->size() < header_len) @@ -81,8 +81,10 @@ bool ReadCRL(base::StringPiece* data, uint32_t num_serials; if (data->size() < sizeof(num_serials)) return false; - // Assumes little endian. - memcpy(&num_serials, data->data(), sizeof(num_serials)); + num_serials = static_cast(data->data()[0]); + num_serials |= static_cast(data->data()[1]) << 8; + num_serials |= static_cast(data->data()[2]) << 16; + num_serials |= static_cast(data->data()[3]) << 24; data->remove_prefix(sizeof(num_serials)); if (num_serials > 32 * 1024 * 1024) // Sanity check. @@ -194,16 +196,6 @@ CRLSet::~CRLSet() = default; // static bool CRLSet::Parse(base::StringPiece data, scoped_refptr* out_crl_set) { TRACE_EVENT0(NetTracingCategory(), "CRLSet::Parse"); -// Other parts of Chrome assume that we're little endian, so we don't lose -// anything by doing this. -#if defined(__BYTE_ORDER) - // Linux check - static_assert(__BYTE_ORDER == __LITTLE_ENDIAN, "assumes little endian"); -#elif defined(__BIG_ENDIAN__) -// Mac check -#error assumes little endian -#endif - std::unique_ptr header_dict(ReadHeader(&data)); if (!header_dict.get()) return false;