Fix possible NPEs and IndexOutOfBoundsExceptions in HTTP/2 Codec (#10640)
Motivation: There are possible NPEs and IndexOutOfBoundsExceptions in HTTP/2 code. Modification: Fixed possible NPEs and IOOBEs Result: Better code
This commit is contained in:
parent
065c39611e
commit
ee3b9a5f7b
@ -147,8 +147,8 @@ abstract class AbstractHttp2StreamChannel extends DefaultAttributeMap implements
|
||||
REQUESTED
|
||||
}
|
||||
|
||||
private final AbstractHttp2StreamChannel.Http2StreamChannelConfig config = new Http2StreamChannelConfig(this);
|
||||
private final AbstractHttp2StreamChannel.Http2ChannelUnsafe unsafe = new Http2ChannelUnsafe();
|
||||
private final Http2StreamChannelConfig config = new Http2StreamChannelConfig(this);
|
||||
private final Http2ChannelUnsafe unsafe = new Http2ChannelUnsafe();
|
||||
private final ChannelId channelId;
|
||||
private final ChannelPipeline pipeline;
|
||||
private final DefaultHttp2FrameStream stream;
|
||||
@ -258,7 +258,7 @@ abstract class AbstractHttp2StreamChannel extends DefaultAttributeMap implements
|
||||
final int oldValue = unwritable;
|
||||
final int newValue = oldValue | 1;
|
||||
if (UNWRITABLE_UPDATER.compareAndSet(this, oldValue, newValue)) {
|
||||
if (oldValue == 0 && newValue != 0) {
|
||||
if (oldValue == 0) {
|
||||
fireChannelWritabilityChanged(invokeLater);
|
||||
}
|
||||
break;
|
||||
|
@ -507,10 +507,6 @@ public class DefaultHttp2ConnectionDecoder implements Http2ConnectionDecoder {
|
||||
return;
|
||||
}
|
||||
|
||||
if (parentStream == null) {
|
||||
throw connectionError(PROTOCOL_ERROR, "Stream %d does not exist", streamId);
|
||||
}
|
||||
|
||||
switch (parentStream.state()) {
|
||||
case OPEN:
|
||||
case HALF_CLOSED_LOCAL:
|
||||
|
@ -219,7 +219,7 @@ public class DefaultHttp2FrameWriter implements Http2FrameWriter, Http2FrameSize
|
||||
ctx.write(frameHeader2, promiseAggregator.newPromise());
|
||||
|
||||
// Write the payload.
|
||||
if (frameDataBytes != 0) {
|
||||
if (frameDataBytes != 0 && data != null) { // Make sure Data is not null
|
||||
if (remainingData == 0) {
|
||||
ByteBuf lastFrame = data.readSlice(frameDataBytes);
|
||||
data = null;
|
||||
|
@ -183,6 +183,7 @@ final class HpackDynamicTable {
|
||||
|
||||
// initially length will be 0 so there will be no copy
|
||||
int len = length();
|
||||
if (hpackHeaderFields != null) {
|
||||
int cursor = tail;
|
||||
for (int i = 0; i < len; i++) {
|
||||
HpackHeaderField entry = hpackHeaderFields[cursor++];
|
||||
@ -191,6 +192,7 @@ final class HpackDynamicTable {
|
||||
cursor = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tail = 0;
|
||||
head = tail + len;
|
||||
|
@ -823,12 +823,14 @@ public final class ReadOnlyHttp2Headers implements Http2Headers {
|
||||
for (; i < current.length; i += 2) {
|
||||
AsciiString roName = current[i];
|
||||
if (roName.hashCode() == nameHash && roName.contentEqualsIgnoreCase(name)) {
|
||||
if (i + 1 < current.length) {
|
||||
next = current[i + 1];
|
||||
i += 2;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (i >= current.length && current == pseudoHeaders) {
|
||||
if (current == pseudoHeaders) {
|
||||
i = 0;
|
||||
current = otherHeaders;
|
||||
calculateNext();
|
||||
|
Loading…
Reference in New Issue
Block a user