Skip to content

Commit

Permalink
Merge branch 'master' into development/thundershark-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
pwielders authored Oct 13, 2023
2 parents 4350aab + edbc9ac commit f3a2760
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 15 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/Build Thunder on Windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ jobs:

- name: Build Thunder
shell: cmd
run: |
run: >
cd ThunderOnWindows
"%devEnv%" /Build "${{matrix.type}}|x${{matrix.version}}" /Project "%bridge%" "%solution%"
"%devEnv%" /Build "${{matrix.type}}|x${{matrix.version}}" /Project "%comProcess%" "%solution%"
&& "%devEnv%" /Build "${{matrix.type}}|x${{matrix.version}}" /Project "%bridge%" "%solution%"
&& "%devEnv%" /Build "${{matrix.type}}|x${{matrix.version}}" /Project "%comProcess%" "%solution%"
- name: Tar files
run: tar -czvf ${{matrix.type}}${{matrix.version}}.tar.gz artifacts
Expand Down
4 changes: 4 additions & 0 deletions Source/core/TextStreamRedirectType.h
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,11 @@ namespace Core {
if (length > 0) {
dst.resize(length);
vsnprintf((char*)dst.data(), dst.size() + 1, format, ap);
#ifdef __WINDOWS__
_write(_channel.Origin(), dst.c_str(), length);
#else
write(_channel.Origin(), dst.c_str(), length);
#endif
}
else {
dst = "Format error! format: ";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,11 +289,13 @@ namespace Core {

const uint16_t payloadSize((nFds <= maxFdsPerRequest) ? (sizeof(int) * nFds) : (sizeof(int) * maxFdsPerRequest));

char buf[CMSG_SPACE(payloadSize)];
memset(buf, 0, sizeof(buf));
char* buf = static_cast<char*>(ALLOCA(CMSG_SPACE(payloadSize)));
memset(buf, 0, CMSG_SPACE(payloadSize));

uint32_t identifier(id);
struct iovec io = { .iov_base = &identifier, .iov_len = sizeof(identifier) };
struct iovec io {
&identifier, sizeof(identifier)
};

msg.msg_name = &client;
msg.msg_namelen = length;
Expand Down Expand Up @@ -354,7 +356,9 @@ namespace Core {
memset(buf, 0, sizeof(buf));

uint32_t identifier;
struct iovec io = { .iov_base = &identifier, .iov_len = sizeof(identifier) };
struct iovec io {
&identifier, sizeof(identifier)
};

msg.msg_name = NULL;
msg.msg_namelen = 0;
Expand Down
18 changes: 10 additions & 8 deletions Source/websocket/WebSocketLink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,8 @@ namespace Web {
::memmove(&dataFrame[2], &(dataFrame[4]), usedSize);
}
} else {
uint32_t value;
// Generate a new mask value
uint8_t maskKey[4];
Crypto::Random(value);
maskKey[0] = value & 0xFF;
maskKey[1] = (value >> 8) & 0xFF;
maskKey[2] = (value >> 16) & 0xFF;
maskKey[3] = (value >> 24) & 0xFF;
GenerateMaskKey(maskKey);

// Mask and insert the bytes on the right spots
uint8_t* source = &dataFrame[usedSize - 1 + 4];
Expand Down Expand Up @@ -138,7 +132,7 @@ namespace Web {
result += usedSize;
}

if (((_controlStatus & (REQUEST_CLOSE | REQUEST_PING | REQUEST_PONG)) != 0) && ((result + 1) < maxSendSize)) {
if (((_controlStatus & (REQUEST_CLOSE | REQUEST_PING | REQUEST_PONG)) != 0) && (result + (((_setFlags & MASKING_FRAME) != 0) ? 6 : 2) < maxSendSize)) {
if ((_controlStatus & REQUEST_CLOSE) != 0) {
dataFrame[result++] = FINISHING_FRAME | Protocol::CLOSE;
_controlStatus &= (~REQUEST_CLOSE);
Expand All @@ -154,6 +148,14 @@ namespace Web {
_controlStatus &= (~REQUEST_PONG);
dataFrame[result++] = (_setFlags & MASKING_FRAME);
}

if ((_setFlags & MASKING_FRAME) != 0) {
// Now it seems only control message, hence append with masking keys
uint8_t maskKey[4];
GenerateMaskKey(maskKey);
::memcpy(&dataFrame[result], &maskKey, 4);
result += 4;
}
}

return (result);
Expand Down
12 changes: 12 additions & 0 deletions Source/websocket/WebSocketLink.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,18 @@ namespace Web {
uint16_t Encoder(uint8_t* dataFrame, const uint16_t maxSendSize, const uint16_t usedSize);
uint16_t Decoder(uint8_t* dataFrame, uint16_t& receivedSize);

private:
inline void GenerateMaskKey(uint8_t *maskKey)
{
uint32_t value;
// Generate a new mask value
Crypto::Random(value);
maskKey[0] = value & 0xFF;
maskKey[1] = (value >> 8) & 0xFF;
maskKey[2] = (value >> 16) & 0xFF;
maskKey[3] = (value >> 24) & 0xFF;
}

private:
uint8_t _setFlags;
uint8_t _progressInfo;
Expand Down

0 comments on commit f3a2760

Please sign in to comment.