Fix misaligned websocket reads
This commit is contained in:
@@ -72,6 +72,13 @@ public:
|
|||||||
|
|
||||||
namespace protocol {
|
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 */
|
/* Byte swap for little-endian systems */
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T cond_byte_swap(T value) {
|
T cond_byte_swap(T value) {
|
||||||
@@ -399,12 +406,12 @@ public:
|
|||||||
} else if (payloadLength(src) == 126) {
|
} else if (payloadLength(src) == 126) {
|
||||||
if (length < MEDIUM_MESSAGE_HEADER) {
|
if (length < MEDIUM_MESSAGE_HEADER) {
|
||||||
break;
|
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;
|
return;
|
||||||
}
|
}
|
||||||
} else if (length < LONG_MESSAGE_HEADER) {
|
} else if (length < LONG_MESSAGE_HEADER) {
|
||||||
break;
|
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;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user