runtime: IPAddress.Parse("4294967296") does not throw FormatException on OS X

System.Net.IPAddress.Parse(“4294967296”) does not throw FormatException on OS X.

$ uname -a
Darwin 15.6.0 Darwin Kernel Version 15.6.0: Mon Aug 29 20:21:34 PDT 2016; root:xnu-3248.60.11~1/RELEASE_X86_64 x86_64 i386 MacBookPro11,5 Darwin

$ dotnet --version
1.0.0-preview2-003121

Steps to reproduce

mkdir foo
cd foo
dotnet new
dotnet restore
sed -i '9i Console.WriteLine(System.Net.IPAddress.Parse("4294967296"));' Program.cs
dotnet run

The sed command writes Console.WriteLine(System.Net.IPAddress.Parse("4294967296")); to line 9 in Program.cs

IPAddress.Parse returns 0.0.0.0 on my Mac when using dotnet run.

$ dotnet run
Project bug (.NETCoreApp,Version=v1.0) was previously compiled. Skipping compilation.
0.0.0.0
Hello World!

On Windows, Ubuntu, Docker on Mac, and Mono on Mac I get the expected FormatException:

$ mono bin/Debug/netcoreapp1.0/bug.dll 

Unhandled Exception:
System.FormatException: An invalid IP address was specified.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 16 (14 by maintainers)

Most upvoted comments

I’m working on this now. I currently have the managed implementation being used for Unix, but it’ll be trivial to rip out the PAL and just use the managed implementation everywhere.

Thanks, @akoeplinger. @cipop, @pgavlin, why did we move away from this implementation for corefx? i.e. why didn’t we keep using the managed implementation that desktop is using? https://referencesource.microsoft.com/#System/net/System/Net/IPAddress.cs,272