Skip to content

Fix NPE when upgrade message fails to aggregate (#14816)#14831

Merged
normanmaurer merged 1 commit intonetty:4.2from
chrisvest:4.2-upgrade-npe
Feb 18, 2025
Merged

Fix NPE when upgrade message fails to aggregate (#14816)#14831
normanmaurer merged 1 commit intonetty:4.2from
chrisvest:4.2-upgrade-npe

Conversation

@chrisvest
Copy link
Copy Markdown
Member

Motivation:

When an HTTP message fails to aggregate, for example due to an invalid 'Expect' header, MessageAggregator does not produce a FullHttpRequest. HttpServerUpgradeHandler would then continue with the next request, wrongly believing it to be an upgrade request, even though only the previous one was. This produces an NPE:

Caused by: java.lang.NullPointerException: Cannot invoke "java.lang.CharSequence.length()" because "header" is null
	at io.netty.handler.codec.http.HttpServerUpgradeHandler.splitHeader(HttpServerUpgradeHandler.java:429)
	at io.netty.handler.codec.http.HttpServerUpgradeHandler.upgrade(HttpServerUpgradeHandler.java:328)
	at io.netty.handler.codec.http.HttpServerUpgradeHandler.decode(HttpServerUpgradeHandler.java:290)
	at io.netty.handler.codec.http.HttpServerUpgradeHandler.decode(HttpServerUpgradeHandler.java:40)
	at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:91)
	... 35 common frames omitted

Modification:

When the upgrade handler sees a LastHttpContent, cancel the current upgrade and cancel aggregation.

Result:

No NPE for this input.

Found by fuzzing.

Motivation:

When an HTTP message fails to aggregate, for example due to an invalid
'Expect' header, MessageAggregator does not produce a FullHttpRequest.
HttpServerUpgradeHandler would then continue with the next request,
wrongly believing it to be an upgrade request, even though only the
previous one was. This produces an NPE:

```
Caused by: java.lang.NullPointerException: Cannot invoke "java.lang.CharSequence.length()" because "header" is null
	at io.netty.handler.codec.http.HttpServerUpgradeHandler.splitHeader(HttpServerUpgradeHandler.java:429)
	at io.netty.handler.codec.http.HttpServerUpgradeHandler.upgrade(HttpServerUpgradeHandler.java:328)
	at io.netty.handler.codec.http.HttpServerUpgradeHandler.decode(HttpServerUpgradeHandler.java:290)
	at io.netty.handler.codec.http.HttpServerUpgradeHandler.decode(HttpServerUpgradeHandler.java:40)
	at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:91)
	... 35 common frames omitted
```

Modification:

When the upgrade handler sees a LastHttpContent, cancel the current
upgrade and cancel aggregation.

Result:

No NPE for this input.

Found by fuzzing.
@chrisvest chrisvest added this to the 4.2.0.RC4 milestone Feb 18, 2025
@normanmaurer normanmaurer merged commit 3f29394 into netty:4.2 Feb 18, 2025
14 of 15 checks passed
@chrisvest chrisvest deleted the 4.2-upgrade-npe branch February 18, 2025 15:54
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.

3 participants