MessageBuffer: use CopyFromBufferOrDie()

Update ConsumeNextMessage() to make use of
local_utils::CopyFromBufferOrDie(). This (hopefully)
accomplishes two things:
- makes the code a bit more obvious, and
- makes the code more consistent with CommandProcessor

Along the way: fix a bug in the way that we check
that the MessageBuffer contains enough bytes for
a LengthHeader.

(Previously, we were checking that the LengthHeader
fit within the memory bounds of |data_|. Really,
though, we should check that the LengthHeader fits
within the populated area of |data_|.)

Bug: 31971382
Test: ./runtests.sh (on bullhead)
Change-Id: Ie3a4c38fefb69a3212142a53e79fdc720af6c601
diff --git a/message_buffer.cpp b/message_buffer.cpp
index 12b41be..219aeec 100644
--- a/message_buffer.cpp
+++ b/message_buffer.cpp
@@ -24,6 +24,8 @@
 namespace android {
 namespace wifilogd {
 
+using local_utils::CopyFromBufferOrDie;
+
 MessageBuffer::MessageBuffer(size_t size)
     : data_(new uint8_t[size]), capacity_(size), read_pos_(0), write_pos_(0) {
   CHECK(size > GetHeaderSize());
@@ -62,10 +64,8 @@
     return {nullptr, 0};
   }
 
-  LengthHeader header;
-  const uint8_t* header_start = data_.get() + read_pos_;
-  CHECK(header_start + sizeof(header) <= data_.get() + capacity_);
-  std::memcpy(&header, header_start, sizeof(header));
+  const auto& header = CopyFromBufferOrDie<LengthHeader>(
+      data_.get() + read_pos_, GetReadableSize());
   read_pos_ += sizeof(header);
 
   const uint8_t* payload_start = data_.get() + read_pos_;