-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
src: make Sec-WebSocket-Key check case-insensitive #7248
src: make Sec-WebSocket-Key check case-insensitive #7248
Conversation
@@ -445,7 +445,7 @@ static int header_value_cb(http_parser* parser, const char* at, size_t length) { | |||
struct http_parsing_state_s* state = (struct http_parsing_state_s*) | |||
(reinterpret_cast<inspector_socket_t*>(parser->data))->http_parsing_state; | |||
state->parsing_value = true; | |||
if (state->current_header && strncmp(state->current_header, | |||
if (state->current_header && strncasecmp(state->current_header, | |||
SEC_WEBSOCKET_KEY_HEADER, | |||
sizeof(SEC_WEBSOCKET_KEY_HEADER)) == 0) { |
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.
You may want to keep the arguments aligned here :-)
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.
fixed. Needing to put things on a new line as the sizeof
line was spilling over 80 characters
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.
Sorry to be so nit-picky, but ideally the subsequent arguments of strncasecmp
should start at the same column at which the first one does (basically like they were before)
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.
got it this time I think :P
9d97d5b
to
f3baec9
Compare
LGTM pending @addaleax's comment. |
f3baec9
to
9611926
Compare
if (state->current_header && | ||
strncasecmp(state->current_header, | ||
SEC_WEBSOCKET_KEY_HEADER, | ||
sizeof(SEC_WEBSOCKET_KEY_HEADER)) == 0) { |
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.
Can you add a version of StringEqualNoCase()
that takes a size parameter and use that?
Style: arguments should line up here.
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.
lining up the arguments pushes over 80 characters... what is the best way to deal with that?
edit: nvm got the line up... looking into StringEqualNoCase
9611926
to
8ee040e
Compare
lgtm |
8ee040e
to
ffb8530
Compare
updated based on @bnoordhuis' suggestions. PTAL |
@thealphanerd now that you have added |
ffb8530
to
f7269c7
Compare
@ofrobots updated with test. Let me know if you would like some more cases |
f7269c7
to
071889c
Compare
for (int i = 0; i < length; i++) { | ||
if (ToLower(a[i]) != ToLower(b[i])) | ||
return false; | ||
if (a[i] == '\0') |
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 we are guaranteed at this point that if a[i]
is null
, then b[i]
is also null
. I think you can simply return true
if a[i]
is null
. The second if
below can simply be dropped.
It would be good to add a test that compares: "abc\0abc"
and "abc\0xyz"
. Your function should (already does) return true for this. This matches the semantics of strncmp
.
LGTM w/ comment. |
071889c
to
493e0ce
Compare
Updated to address @ofrobots comments. PTAL edit: |
493e0ce
to
263d9ef
Compare
@@ -1,4 +1,5 @@ | |||
#include "inspector_socket.h" | |||
#include "util-inl.h" |
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.
#include "util.h"
first.
263d9ef
to
ec6604a
Compare
Updated based on @bnoordhuis's suggestions PTAL |
@@ -219,6 +219,16 @@ bool StringEqualNoCase(const char* a, const char* b) { | |||
return false; | |||
} | |||
|
|||
bool StringEqualNoCaseN(const char* a, const char* b, size_t length) { | |||
for (int i = 0; i < length; i++) { |
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.
size_t
LGTM with comment. |
ec6604a
to
f5c8dc6
Compare
updated PTAL |
If there are no other concerns with this PR I will merge it tomorrow morning |
f5c8dc6
to
02fd124
Compare
Current case sensitive comparison is breaking netty-based WS clients. replace strncmp with strncasecmp Fixes: nodejs#7247 PR-URL: nodejs#7248 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
02fd124
to
f1d1071
Compare
Checklist
make -j4 test
(UNIX) orvcbuild test nosign
(Windows) passesAffected core subsystem(s)
src
Description of change
Current case sensitive comparison is breaking netty-based WS clients.
replace strncmp with strncasecmp
Fixes: #7247