Commit d909c711 authored by Edward Catmur's avatar Edward Catmur

Don't bind Header reference to a null pointer.

If recvData is empty, recvData.begin() is a null pointer and binding a Header reference to it is invalid.

Detected by -fsanitize=null.
parent 065181a1
......@@ -1953,8 +1953,7 @@ public:
}
kj::Promise<Message> receive() override {
auto& recvHeader = *reinterpret_cast<Header*>(recvData.begin());
size_t headerSize = recvHeader.headerSize(recvData.size());
size_t headerSize = Header::headerSize(recvData.begin(), recvData.size());
if (headerSize > recvData.size()) {
if (recvData.begin() != recvBuffer.begin()) {
......@@ -1982,6 +1981,8 @@ public:
});
}
auto& recvHeader = *reinterpret_cast<Header*>(recvData.begin());
recvData = recvData.slice(headerSize, recvData.size());
size_t payloadLen = recvHeader.getPayloadLen();
......@@ -2231,7 +2232,7 @@ private:
}
}
size_t headerSize(size_t sizeSoFar) {
static size_t headerSize(byte const* bytes, size_t sizeSoFar) {
if (sizeSoFar < 2) return 2;
size_t required = 2;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment