Skip to content

Conversation

VelorumS
Copy link

The problem is when the client advertises "protocol": ["binary", "base64"], the server picks base64. The server should prefer the first one.

It's an issue when the client had this configuration as a fix to the 400 Client must support 'binary' or 'base64' protocol error with noVNC and old websockify + VNC: novnc/noVNC#1276 (comment) . Today it seems that noVNC doesn't do base64 any more. Although it's now incorrect for the client to advertise both protocols, it's not intuitive that "protocol": ["binary", "base64"] doesn't work while "protocol": ["binary"] does.

Relevant PR/issue:

#342

novnc/noVNC#1310

Copy link
Member

@bk138 bk138 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! Some work left to do 😇

}

if ((protocol) && (strstr(protocol, "base64"))) {
proto_binary = strstr(protocol, "binary");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's UB if protocol is NULL. Maybe just inline those calls?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a NULL check.

if ((protocol) && (strstr(protocol, "base64"))) {
proto_binary = strstr(protocol, "binary");
proto_base64 = strstr(protocol, "base64");
if ((protocol) && (proto_base64 && (!proto_binary || proto_base64 < proto_binary))) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After the ||, you're comparing char*? That can't be right.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comparing pointers is the priority check: the one that comes first has the priority.

return FALSE;
}

if ((protocol) && (strstr(protocol, "base64"))) {
Copy link
Member

@bk138 bk138 Oct 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All in all: why not simply swap the if and else blocks?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some articles mention the list of protocols like "a list of sub-protocols that the client can handle in the priority order". So it's logical to respect the priority.

@VelorumS VelorumS force-pushed the ws-subproto-priority branch from fe6607c to 76a0f50 Compare October 27, 2023 06:54
@VelorumS VelorumS requested a review from bk138 October 31, 2023 07:17
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

Successfully merging this pull request may close these issues.

2 participants