Skip to content

Commit

Permalink
Consolidate CID checks in QuicPacketValidateInvariant (microsoft#277)
Browse files Browse the repository at this point in the history
  • Loading branch information
maolson-msft authored Mar 26, 2020
1 parent b9485d9 commit c972c20
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 23 deletions.
16 changes: 0 additions & 16 deletions src/core/binding.c
Original file line number Diff line number Diff line change
Expand Up @@ -913,22 +913,6 @@ QuicBindingPreprocessDatagram(
return FALSE;
}

if (Binding->Exclusive) {
if (Packet->DestCidLen != 0) {
QuicPacketLogDrop(Binding, Packet, "Non-zero length CID on exclusive binding");
return FALSE;
}
} else {
if (Packet->DestCidLen == 0) {
QuicPacketLogDrop(Binding, Packet, "Zero length CID on non-exclusive binding");
return FALSE;

} else if (Packet->DestCidLen < QUIC_MIN_INITIAL_CONNECTION_ID_LENGTH) {
QuicPacketLogDrop(Binding, Packet, "Less than min length CID on non-exclusive binding");
return FALSE;
}
}

if (Packet->Invariant->IsLongHeader) {
//
// Validate we support this long header packet version.
Expand Down
24 changes: 17 additions & 7 deletions src/core/packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,21 @@ QuicPacketValidateInvariant(
QuicPacketLogDrop(Owner, Packet, "LH no room for DestCid");
return FALSE;
}
if (IsBindingShared && DestCidLen == 0) {
QuicPacketLogDrop(Owner, Packet, "Zero length DestCid");
return FALSE;
if (IsBindingShared) {
if (DestCidLen == 0) {
QuicPacketLogDrop(Owner, Packet, "Zero length DestCid");
return FALSE;
} else if (DestCidLen < QUIC_MIN_INITIAL_CONNECTION_ID_LENGTH) {
QuicPacketLogDrop(Owner, Packet, "Less than min length CID on non-exclusive binding");
return FALSE;
}
} else {
if (DestCidLen != 0) {
QuicPacketLogDrop(Owner, Packet, "Non-zero length CID on exclusive binding");
return FALSE;
}
}

DestCid = Packet->Invariant->LONG_HDR.DestCid;

SourceCidLen = *(DestCid + DestCidLen);
Expand Down Expand Up @@ -129,8 +140,8 @@ QuicPacketValidateInvariant(
if (Packet->DestCid != NULL) {

//
// The CID(s) have already been previously set for this UDP datagram.
// Make sure they match.
// CID(s) are cached from a previous packet in the datagram. Check that
// they match.
//

if (Packet->DestCidLen != DestCidLen ||
Expand All @@ -153,8 +164,7 @@ QuicPacketValidateInvariant(
} else {

//
// The first QUIC packet in the datagram, save the CIDs with the receive
// context.
// This is the first packet in the datagram. Cache the CIDs.
//

Packet->DestCidLen = DestCidLen;
Expand Down

0 comments on commit c972c20

Please sign in to comment.