Skip to content

Commit

Permalink
Fix unmasking of received data for DataLink over WebSockets
Browse files Browse the repository at this point in the history
  • Loading branch information
Chad Trabant committed Feb 23, 2018
1 parent 79d65d5 commit a5ae092
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 19 deletions.
3 changes: 3 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
2018.054:
- Fix unmasking of received data for DataLink over WebSockets.

2018.050:
- Change output of /streamids to always be only stream IDs (no type).

Expand Down
27 changes: 9 additions & 18 deletions src/clients.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* You should have received a copy of the GNU General Public License
* along with ringserver. If not, see http://www.gnu.org/licenses/.
*
* Modified: 2017.012
* Modified: 2018.054
**************************************************************************/

#include <errno.h>
Expand Down Expand Up @@ -521,17 +521,6 @@ ClientRecv (ClientInfo *cinfo)
nread = RecvLine (cinfo);
}

/* Check WebSocket payload length against what was recv'ed, accounting for
1 or 2 dropped terminators. */
if (cinfo->websocket &&
nread != wslength &&
nread != wslength - 1 &&
nread != wslength - 2)
{
lprintf (1, "[%s] WebSocket payload length (%" PRId64 ") does not match bytes read (%d)",
cinfo->hostname, wslength, nread);
}

return nread;
} /* End of ClientRecv() */

Expand Down Expand Up @@ -732,6 +721,7 @@ RecvData (ClientInfo *cinfo, char *buffer, size_t buflen)
{
int nrecv;
int nread = 0;
int idx;
char *bptr = buffer;

fd_set readset;
Expand Down Expand Up @@ -791,8 +781,8 @@ RecvData (ClientInfo *cinfo, char *buffer, size_t buflen)
/* Unmask received data if a mask was supplied as WebSocket */
if (cinfo->wsmask.one != 0)
{
bptr = cinfo->recvbuf;
for (; cinfo->wsmaskidx < nread; bptr++, cinfo->wsmaskidx++)
bptr = buffer;
for (idx = 0; idx < nread; idx++, bptr++, cinfo->wsmaskidx++)
*bptr = *bptr ^ cinfo->wsmask.four[cinfo->wsmaskidx % 4];
}

Expand Down Expand Up @@ -826,6 +816,7 @@ RecvCmd (ClientInfo *cinfo)
int nreadtotal = 0;
int nrecv;
int pass;
int idx;
uint8_t nreq;
char *bptr;

Expand Down Expand Up @@ -916,7 +907,7 @@ RecvCmd (ClientInfo *cinfo)
if (cinfo->wsmask.one != 0)
{
bptr = cinfo->recvbuf;
for (; cinfo->wsmaskidx < nread; bptr++, cinfo->wsmaskidx++)
for (idx = 0; idx < nread; idx++, bptr++, cinfo->wsmaskidx++)
*bptr = *bptr ^ cinfo->wsmask.four[cinfo->wsmaskidx % 4];
}

Expand All @@ -940,7 +931,7 @@ RecvCmd (ClientInfo *cinfo)
}
else
{
lprintf (2, "[%s] Error verifying DataLink sequence bytes (%c%c) or HTTP",
lprintf (2, "[%s] Error verifying DataLink sequence bytes (%c%c)",
cinfo->hostname, *(cinfo->recvbuf), *(cinfo->recvbuf + 1));
return -2;
}
Expand All @@ -957,13 +948,13 @@ RecvCmd (ClientInfo *cinfo)
if (cinfo->wsmask.one != 0)
{
bptr = cinfo->recvbuf;
for (; cinfo->wsmaskidx < nread; bptr++, cinfo->wsmaskidx++)
for (idx = 0; idx < nreq; idx++, bptr++, cinfo->wsmaskidx++)
*bptr = *bptr ^ cinfo->wsmask.four[cinfo->wsmaskidx % 4];
}

/* Make sure buffer is NULL terminated. The command string is
* allowed to be <= (cinfo->recvbuflen - 1), so this should be safe. */
*(cinfo->recvbuf + nread) = '\0';
*(cinfo->recvbuf + nreq) = '\0';

return nreadtotal;
} /* End of RecvCmd() */
Expand Down
2 changes: 1 addition & 1 deletion src/ringserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extern "C" {
#endif

#define PACKAGE "ringserver"
#define VERSION "2018.050"
#define VERSION "2018.054"

/* Thread data flags */
#define TDF_SPAWNING (1<<0) /* Thread is now spawning */
Expand Down

0 comments on commit a5ae092

Please sign in to comment.