Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cwebsocket_write_data fails to write over 65535 bytes and htonl64 fails. #4

Open
vishalhosakere opened this issue Sep 12, 2018 · 1 comment

Comments

@vishalhosakere
Copy link

The frame headers are wrong for frames with payload length over 65535. The below line in cwebsocket_write_data adds 10 additional bytes to header length when it should be only 8.

uint32_t header_length = 6 + (payload_len > 125 ? 2 : 0) + (payload_len > 0xffff ? 8 : 0);

Changing this to the below solves it.

uint32_t header_length = 6 + (payload_len > 125 ? 2 : 0) + (payload_len > 0xffff ? 6 : 0);

In common.h

#define htonl64(p) {\
	(char)(((p & ((uint64_t)0xff <<  0)) >>  0) & 0xff), (char)(((p & ((uint64_t)0xff <<  8)) >>  8) & 0xff), \
	(char)(((p & ((uint64_t)0xff << 16)) >> 16) & 0xff), (char)(((p & ((uint64_t)0xff << 24)) >> 24) & 0xff), \
	(char)(((p & ((uint64_t)0xff << 32)) >> 32) & 0xff), (char)(((p & ((uint64_t)0xff << 40)) >> 40) & 0xff), \
(char)(((p & ((uint64_t)0xff << 48)) >> 48) & 0xff), (char)(((p & ((uint64_t)0xff << 56)) >> 56) & 0xff) }

needs to be changed to

#define htonl64(p) {\
    (char)(((p & ((uint64_t)0xff << 56)) >> 56) & 0xff), (char)(((p & ((uint64_t)0xff << 48)) >> 48) & 0xff), \
    (char)(((p & ((uint64_t)0xff << 40)) >> 40) & 0xff), (char)(((p & ((uint64_t)0xff << 32)) >> 32) & 0xff), \
    (char)(((p & ((uint64_t)0xff << 24)) >> 24) & 0xff), (char)(((p & ((uint64_t)0xff << 16)) >> 16) & 0xff), \
    (char)(((p & ((uint64_t)0xff <<  8)) >>  8) & 0xff), (char)(((p & ((uint64_t)0xff <<  0)) >>  0) & 0xff) }
@jeremyhahn
Copy link
Owner

Thanks for your report. Are you able to open a pull request?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants