Karlson2k / libmicrohttpd

GNU libmicrohttpd repository unofficial mirror on GitHub
https://www.gnu.org/software/libmicrohttpd/
Other
101 stars 29 forks source link

bug in BASE64Encode in websocket_threaded_example.c #33

Open timredfern opened 2 months ago

timredfern commented 2 months ago

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 commented 2 months ago

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.