Fix misaligned websocket reads

This commit is contained in:
Alex Hultman
2019-04-15 22:15:45 +02:00
parent b36607dac6
commit 7ea680e187
+9 -2
View File
@@ -72,6 +72,13 @@ public:
namespace protocol {
template <typename T>
T bit_cast(char *c) {
T val;
memcpy(&val, c, sizeof(T));
return val;
}
/* Byte swap for little-endian systems */
template <typename T>
T cond_byte_swap(T value) {
@@ -399,12 +406,12 @@ public:
} else if (payloadLength(src) == 126) {
if (length < MEDIUM_MESSAGE_HEADER) {
break;
} else if(consumeMessage<MEDIUM_MESSAGE_HEADER, uint16_t>(protocol::cond_byte_swap<uint16_t>(*(uint16_t *) &src[2]), src, length, wState, user)) {
} else if(consumeMessage<MEDIUM_MESSAGE_HEADER, uint16_t>(protocol::cond_byte_swap<uint16_t>(protocol::bit_cast<uint16_t>(src + 2)), src, length, wState, user)) {
return;
}
} else if (length < LONG_MESSAGE_HEADER) {
break;
} else if (consumeMessage<LONG_MESSAGE_HEADER, uint64_t>(protocol::cond_byte_swap<uint64_t>(*(uint64_t *) &src[2]), src, length, wState, user)) {
} else if (consumeMessage<LONG_MESSAGE_HEADER, uint64_t>(protocol::cond_byte_swap<uint64_t>(protocol::bit_cast<uint64_t>(src + 2)), src, length, wState, user)) {
return;
}
}