Skip to content
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

Refactor pchar_parse() to use switch() #10398

Merged
merged 1 commit into from
Apr 14, 2017
Merged

Refactor pchar_parse() to use switch() #10398

merged 1 commit into from
Apr 14, 2017

Conversation

ipylypiv
Copy link
Contributor

Comparisons c == '$' and c == '&' are present two times inside if statement.

@grpc-kokoro
Copy link

Thanks for your pull request. The automated tests will run as soon as one of the admins verifies this change is ok for us to run on our infrastructure.

13 similar comments
@grpc-kokoro
Copy link

Thanks for your pull request. The automated tests will run as soon as one of the admins verifies this change is ok for us to run on our infrastructure.

@grpc-kokoro
Copy link

Thanks for your pull request. The automated tests will run as soon as one of the admins verifies this change is ok for us to run on our infrastructure.

@grpc-kokoro
Copy link

Thanks for your pull request. The automated tests will run as soon as one of the admins verifies this change is ok for us to run on our infrastructure.

@grpc-kokoro
Copy link

Thanks for your pull request. The automated tests will run as soon as one of the admins verifies this change is ok for us to run on our infrastructure.

@grpc-kokoro
Copy link

Thanks for your pull request. The automated tests will run as soon as one of the admins verifies this change is ok for us to run on our infrastructure.

@grpc-kokoro
Copy link

Thanks for your pull request. The automated tests will run as soon as one of the admins verifies this change is ok for us to run on our infrastructure.

@grpc-kokoro
Copy link

Thanks for your pull request. The automated tests will run as soon as one of the admins verifies this change is ok for us to run on our infrastructure.

@grpc-kokoro
Copy link

Thanks for your pull request. The automated tests will run as soon as one of the admins verifies this change is ok for us to run on our infrastructure.

@grpc-kokoro
Copy link

Thanks for your pull request. The automated tests will run as soon as one of the admins verifies this change is ok for us to run on our infrastructure.

@grpc-kokoro
Copy link

Thanks for your pull request. The automated tests will run as soon as one of the admins verifies this change is ok for us to run on our infrastructure.

@grpc-kokoro
Copy link

Thanks for your pull request. The automated tests will run as soon as one of the admins verifies this change is ok for us to run on our infrastructure.

@grpc-kokoro
Copy link

Thanks for your pull request. The automated tests will run as soon as one of the admins verifies this change is ok for us to run on our infrastructure.

@grpc-kokoro
Copy link

Thanks for your pull request. The automated tests will run as soon as one of the admins verifies this change is ok for us to run on our infrastructure.

@ctiller
Copy link
Member

ctiller commented Mar 31, 2017

Jenkins: this is ok to test

@ctiller ctiller self-requested a review March 31, 2017 13:13
@ctiller ctiller self-assigned this Mar 31, 2017
(c == '!' || c == '$' || c == '&' || c == '\'' || c == '$' || c == '&' ||
c == '(' || c == ')' || c == '*' || c == '+' || c == ',' || c == ';' ||
c == '=') /* sub-delims */) {
(c == '!' || c == '$' || c == '&' || c == '\'' ||
Copy link
Member

Choose a reason for hiding this comment

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

This is begging to be converted to a switch..

Copy link
Member

Choose a reason for hiding this comment

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

or some form of LUT

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, agree. I will work on it. Should I create new pull request for that?

@grpc-kokoro
Copy link

No significant performance differences

@ctiller
Copy link
Member

ctiller commented Mar 31, 2017

Could you run tools/distrib/clang-format-code.sh against this and push an update? The formatting is off compared to what our tooling expects. (you'll need docker installed)

@ipylypiv
Copy link
Contributor Author

ipylypiv commented Apr 1, 2017

Sorry about formatting. Fixed.

@grpc-kokoro
Copy link

No significant performance differences

@ctiller
Copy link
Member

ctiller commented Apr 1, 2017 via email

@ipylypiv
Copy link
Contributor Author

ipylypiv commented Apr 3, 2017

During refactoring I have found few issues:

  • missed '@' and ':' characters. By description in comment they are also valid pchars
    pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
  • loop for (j = i + 1; j < 2; j++) executes only once and only when '%' is at position 0 (but intended to be executed twice for each '%')
  • check for end of string if (uri_text[i + 1] == 0 || uri_text[i + 2] == 0) is redundant because 0 ('\0') is not valid hex and this case is handled in the next if statement

Question:
Should we also reject pct-encoded 0 ('\0') byte - %00?
OWASP Null Byte Injection

Would be one additional check:
if (uri_text[i + 1] == '0' && uri_text[i + 2] == '0') return NOT_SET;

@ipylypiv ipylypiv changed the title Remove duplicated comparisons from if statement Refactor pchar_parse() to use switch() Apr 3, 2017
@grpc-kokoro
Copy link

No significant performance differences

@ipylypiv
Copy link
Contributor Author

ipylypiv commented Apr 3, 2017

I am investigating why test failed, and will update my commit to fix that.

@grpc-kokoro
Copy link

No significant performance differences

1 similar comment
@grpc-kokoro
Copy link

No significant performance differences

@ctiller
Copy link
Member

ctiller commented Apr 4, 2017

This looks good: can you merge with head (the file moved) - and re-run clang-format?
Then I'll trigger tests again and see if we can't merge.

@ipylypiv
Copy link
Contributor Author

ipylypiv commented Apr 4, 2017

Sure, I will merge it.

What about %00 handling?

Question:
Should we also reject pct-encoded 0 ('\0') byte - %00?
OWASP Null Byte Injection

Would be one additional check:
if (uri_text[i + 1] == '0' && uri_text[i + 2] == '0') return NOT_SET;

Add previously missed '@' and ':' characters
@grpc-kokoro
Copy link

Performance differences noted:
Benchmark                                                        allocs_per_iteration    atm_add_per_iteration    atm_cas_per_iteration      cpu_time  locks_per_iteration      real_time  writes_per_iteration
---------------------------------------------------------------  ----------------------  -----------------------  -----------------------  ----------  ---------------------  -----------  ----------------------
BM_HpackEncoderEncodeHeader<SingleInternedBinaryElem<1>>/0/16k                                                                                  -9.50                               -9.50
BM_HpackEncoderEncodeHeader<SingleInternedBinaryElem<31>>/0/16k                                                                                -11.50                              -11.50
BM_HpackEncoderEncodeHeader<SingleInternedBinaryElem<3>>/0/16k                                                                                  -9.50                               -9.50
BM_HpackEncoderEncodeHeader<SingleInternedElem>/0/16k                                                                                          -27.50                              -27.50

@ctiller
Copy link
Member

ctiller commented Apr 5, 2017

We use slices throughout for these things, and I think we have a use case down the line for nulls (anonymous uds sockets on Linux) -- unless there's a better standard representation of these.

@ctiller
Copy link
Member

ctiller commented Apr 5, 2017

Jenkins: test this please

@grpc-kokoro
Copy link

No significant performance differences

@ipylypiv
Copy link
Contributor Author

I don't correlate latest build failures with my change. Do I need to do something else here?

@ctiller ctiller merged commit 88ce393 into grpc:master Apr 14, 2017
@ipylypiv ipylypiv deleted the fix_uri_parser branch April 14, 2017 22:10
@lock lock bot locked as resolved and limited conversation to collaborators Jan 23, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants