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

bug in BASE64Encode in websocket_threaded_example.c #33

Open
timredfern opened this issue Aug 9, 2024 · 1 comment
Open

bug in BASE64Encode in websocket_threaded_example.c #33

timredfern opened this issue Aug 9, 2024 · 1 comment

Comments

@timredfern
Copy link

I found an issue in the encoding function in this example. As it stands, the Sec-WebSocket-Key field is returned incorrectly and thus clients that check this cannot connect.

It's only one line to change so I don't know if it's worth getting permission to create a branch or fork the project.

This is the patch:

index 50919190..fec8e631 100644
--- a/src/examples/websocket_threaded_example.c
+++ b/src/examples/websocket_threaded_example.c
@@ -387,7 +387,7 @@ BASE64Encode (const void *in, size_t len, char **output)
     opt[ret++] = cvt[(int) c];
     if (i < len)
     {
-      c = (char) (c | ((data[i] << 2) & 0x3F));
+      c = (char) ((data[i] << 2) & 0x3F);
       if (++i < len)
       {
         c = (char) (c | ((data[i] >> 6) & 0x03));
@Karlson2k
Copy link
Owner

Thanks for the report.
The whole "websockets" part is experimental in MHD (but the "upgrade" functionality is not).

I'll fix this example, as this function is badly broken on platforms with signed char.

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