Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Commit

Permalink
Fix handling of last number in IPv6 address
Browse files Browse the repository at this point in the history
A previous fix for mishandling of certain IPv6 addresses ended up introducing another bug, where we may fail to fail parsing on an address that has too many numbers in its last sequence.  The issue is that, if the string doesn't end with ']', we're not looping around again in the parsing loop, where the beginning of the loop would see the sequence thus far as being too long and error out (the previous fix included removing the adding of a ']' if it didn't exist).  The fix is just to do the check again at the end.
  • Loading branch information
stephentoub committed Sep 1, 2017
1 parent 7868e54 commit ec98bfd
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/System.Net.Primitives/src/System/Net/IPv6AddressHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -242,17 +242,19 @@ internal unsafe static bool IsValidStrict(char* name, int start, ref int end)

if (sequenceLength != 0)
{
if (sequenceLength > 4)
{
return false;
}

++sequenceCount;
lastSequence = i - sequenceLength;
sequenceLength = 0;
}

// these sequence counts are -1 because it is implied in end-of-sequence

const int ExpectedSequenceCount = 8;
return
!expectingNumber &&
(sequenceLength <= 4) &&
(haveCompressor ? (sequenceCount < ExpectedSequenceCount) : (sequenceCount == ExpectedSequenceCount)) &&
!needsClosingBracket;
}
Expand Down

0 comments on commit ec98bfd

Please sign in to comment.