Skip to content

HttpObjectDecoder ignores HTTP trailer header when empty line is rece…#8799

Merged
normanmaurer merged 3 commits into4.1from
parse_trailer_empty_line_in_buffer
Jan 31, 2019
Merged

HttpObjectDecoder ignores HTTP trailer header when empty line is rece…#8799
normanmaurer merged 3 commits into4.1from
parse_trailer_empty_line_in_buffer

Conversation

@normanmaurer
Copy link
Copy Markdown
Member

…ived in seperate ByteBuf

Motivation:

When the empty line that termines the trailers was sent in a seperate ByteBuf we did ignore the previous parsed trailers and just returned none.

Modifications:

  • Correct respect previous parsed trailers.
  • Add unit test.

Result:

Fixes #8736

@normanmaurer
Copy link
Copy Markdown
Member Author

@KowalczykBartek PTAL and thanks for reporting

…ived in seperate ByteBuf

Motivation:

When the empty line that termines the trailers was sent in a seperate ByteBuf we did ignore the previous parsed trailers and just returned none.

Modifications:

- Correct respect previous parsed trailers.
- Add unit test.

Result:

Fixes #8736
@normanmaurer normanmaurer force-pushed the parse_trailer_empty_line_in_buffer branch from 7f702b2 to 322a4ba Compare January 29, 2019 15:48
this.trailer = null;
return trailer;
}
// We have received the empty line which signals the trailer is complete. In this case we need to check if
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This flow is a bit convoluted. How about we remove the surrounding if and make it clear why the condition is there:

if (line.length() == 0 && this.trailer == null) {
  return LastHttpContent.EMPTY_LAST_CONTENT; // optimization
}
// everything from the if today
LastHttpContent trailer = this.trailer;
if (trailer == null) {
...
return trailer;

Alternatively the if could be changed to line.length() > 0 || this.trailer != null, but it's non-obvious why it would be that way. (It's still more obvious than this code, in my mind, though.)

@normanmaurer
Copy link
Copy Markdown
Member Author

@ejona86 PTAL again... I think it's better now (slightly different than what you suggested tho).

@ejona86
Copy link
Copy Markdown
Member

ejona86 commented Jan 29, 2019

My suggestion removed a special-case: it used the normal do-while to handle the "previously saw a trailer". Instead of having 2 special cases like it is now, there was only one: returning EMPTY_LAST_CONTENT. It is makes sense that we should only return EMPTY_LAST_CONTENT if trailer is null, so it's easy to reason about.

With this code as-is, you really have to read more of the do-while loop to verify that the if block is correct. You have to look for things like making sure trailer is set to null.

@normanmaurer
Copy link
Copy Markdown
Member Author

@ejona86 I am still not sure if I did what you suggested but please have a look again 😆

Copy link
Copy Markdown
Member

@ejona86 ejona86 left a comment

Choose a reason for hiding this comment

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

Thanks, yeah, that looks good.

@normanmaurer normanmaurer merged commit 91d3920 into 4.1 Jan 31, 2019
@normanmaurer normanmaurer deleted the parse_trailer_empty_line_in_buffer branch January 31, 2019 19:27
normanmaurer added a commit that referenced this pull request Jan 31, 2019
#8799)

* HttpObjectDecoder ignores HTTP trailer header when empty line is received in seperate ByteBuf

Motivation:

When the empty line that termines the trailers was sent in a seperate ByteBuf we did ignore the previous parsed trailers and just returned none.

Modifications:

- Correct respect previous parsed trailers.
- Add unit test.

Result:

Fixes #8736
dalaro added a commit to dalaro/netty that referenced this pull request Apr 7, 2020
Compared against 4.1.25.6.dse, this tag cherry-picks upstream commits
that fixed bugs in HttpObjectDecoder/HttpRequestDecoder, plus two
intermediate refactoring commits that indirectly affect those bugfix
commits.

What follows is a list of PR links, issue links, CVE links, and hashes
associated with the cherry-picked commits.

Verify we do not receive multiple content-length headers or a content-length and transfer-encoding: chunked header when using HTTP/1.1 (netty#9865)
	https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2020-7238
	netty#9861
	netty#9865

	8494b04

Detect missing colon when parsing http headers with no value (netty#9871)
	GHSA-cqqj-4p63-rrmm
	netty#9866
	netty#9871

	a7c18d4

Fix typos in javadocs (netty#9527)
	skipped

Correctly handle whitespaces in HTTP header names as defined by RFC7230#section-3.2.4 (netty#9585)
	https://nvd.nist.gov/vuln/detail/CVE-2019-16869
	netty#9571
	netty#9585

	39cafcb

Use `AppendableCharSequence.charAtUnsafe(int)` in `HttpObjectDecoder` (netty#9492)
	netty#9492

	85fcf4e

use checkPositive/checkPositiveOrZero (netty#8835)
	netty#8835

	4c64c98

HttpObjectDecoder ignores HTTP trailer header when empty line is rece… (netty#8799)
	netty#8736
	netty#8799

	91d3920
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants