[nghttp2] Work around two possible crashes. (#50)

Context: Our services received (invalid) HTTP2 streams with a disallowed `connection` header. This caused a `nghttp2 error: Invalid HTTP header field was received: frame type: 1, stream: 23, name: [connection], value: [keep-alive]` to be logged, but also caused our serving process to crash subsequently in `onStreamCloseCallback`. After that was worked around, `doOneWrite` was called with a negative length.

This patch does _not_ fix the underlying issue, it only prevents a hard crash of the process until we can migrate to the non-`nghttp2` implementation.
This commit is contained in:
Daniel Alm authored and Cory Benfield committed 2019-03-05 12:19:57 +00:00
1 parent 88bd6d369a
commit 86877eab84
1 file changed
+4 -2
+4 -2
View File
@@ -490,7 +490,9 @@ class NGHTTP2Session {
/// Called when the stream `streamID` is closed.
fileprivate func onStreamCloseCallback(streamID: Int32, errorCode: UInt32) throws {
let streamData = self.streamIDManager.getStreamData(for: streamID)!
guard let streamData = self.streamIDManager.getStreamData(for: streamID) else {
throw NIOHTTP2Errors.NoSuchStream(streamID: HTTP2StreamID(knownID: streamID))
}
// If we have a data provider, pull it out.
let error = NIOHTTP2Errors.StreamClosed(streamID: streamData.streamID,
@@ -648,7 +650,7 @@ class NGHTTP2Session {
let length = nghttp2_session_mem_send(self.session, &data)
// TODO(cory): I think this mishandles DATA frames: they'll say 0, but there may be more frames to
// send. Must investigate.
guard length != 0 else {
guard length > 0 else {
return .noWrite
}
var buffer = self.allocator.buffer(capacity: length)