Skip to content

Commit

Permalink
Fix zero-length CID
Browse files Browse the repository at this point in the history
  • Loading branch information
maskit committed Feb 3, 2020
1 parent 550adb3 commit 99a19e8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion iocore/net/quic/QUICPacket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ QUICPacketR::read_essential_info(Ptr<IOBufferBlock> block, QUICPacketType &type,
if (length_offset + field_len >= static_cast<uint64_t>(len)) {
return false;
}
if (length_offset + field_len + packet_number_len >= static_cast<uint64_t>(len)) {
if (length_offset + field_len + packet_number_len > static_cast<uint64_t>(len)) {
return false;
}
packet_number = QUICTypeUtil::read_QUICPacketNumber(tmp + length_offset + field_len, packet_number_len);
Expand Down
2 changes: 1 addition & 1 deletion iocore/net/quic/QUICTypes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ QUICConnectionId
QUICConnectionId::ZERO()
{
uint8_t zero[MAX_LENGTH] = {0};
return QUICConnectionId(zero, sizeof(zero));
return QUICConnectionId(zero, 0);
}

QUICConnectionId::QUICConnectionId()
Expand Down
27 changes: 27 additions & 0 deletions iocore/net/quic/test/test_QUICPacket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,33 @@ TEST_CASE("read_essential_info", "[quic]")
CHECK(packet_number == 0x01234567);
}

SECTION("Long header packet - INITIAL - 0 length CID")
{
uint8_t input[] = {
0xc2, // Long header, Type: INITIAL
0xff, 0x00, 0x00, 0x19, // Version
0x08, // DCID Len
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, // Destination Connection ID
0x00, // SCID Len
0x00, // Token Length (i), Token (*)
0x42, 0x17, // Length
0x00, 0x00, 0x00 // Packet number
};

Ptr<IOBufferBlock> input_ibb = make_ptr<IOBufferBlock>(new_IOBufferBlock());
input_ibb->set_internal(static_cast<void *>(input), sizeof(input), BUFFER_SIZE_NOT_ALLOCATED);

QUICPacketType type;
QUICVersion version;
QUICConnectionId dcid;
QUICConnectionId scid;
QUICPacketNumber packet_number;
QUICKeyPhase key_phase;
bool result = QUICPacketR::read_essential_info(input_ibb, type, version, dcid, scid, packet_number, 0, key_phase);

REQUIRE(result);
}

SECTION("Long header packet - RETRY")
{
uint8_t input[] = {
Expand Down

0 comments on commit 99a19e8

Please sign in to comment.