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