-
-
Notifications
You must be signed in to change notification settings - Fork 495
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
Fix ws binary/base64 subprotocol priority #595
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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 😇
src/libvncserver/websockets.c
Outdated
@@ -289,13 +291,15 @@ webSocketsHandshake(rfbClientPtr cl, char *scheme) | |||
return FALSE; | |||
} | |||
|
|||
if ((protocol) && (strstr(protocol, "base64"))) { | |||
proto_binary = strstr(protocol, "binary"); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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))) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
@@ -289,13 +291,15 @@ webSocketsHandshake(rfbClientPtr cl, char *scheme) | |||
return FALSE; | |||
} | |||
|
|||
if ((protocol) && (strstr(protocol, "base64"))) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
fe6607c
to
76a0f50
Compare
The problem is when the client advertises
"protocol": ["binary", "base64"]
, the server picksbase64
. 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 dobase64
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