Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit ec98bfd

Browse files
committed
Fix handling of last number in IPv6 address
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.
1 parent 7868e54 commit ec98bfd

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/System.Net.Primitives/src/System/Net/IPv6AddressHelper.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,17 +242,19 @@ internal unsafe static bool IsValidStrict(char* name, int start, ref int end)
242242

243243
if (sequenceLength != 0)
244244
{
245+
if (sequenceLength > 4)
246+
{
247+
return false;
248+
}
249+
245250
++sequenceCount;
246-
lastSequence = i - sequenceLength;
247-
sequenceLength = 0;
248251
}
249252

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

252255
const int ExpectedSequenceCount = 8;
253256
return
254257
!expectingNumber &&
255-
(sequenceLength <= 4) &&
256258
(haveCompressor ? (sequenceCount < ExpectedSequenceCount) : (sequenceCount == ExpectedSequenceCount)) &&
257259
!needsClosingBracket;
258260
}

0 commit comments

Comments
 (0)