Bug 2363 - System.Uri:CheckHostName: off-by-one error in label length check
Summary: System.Uri:CheckHostName: off-by-one error in label length check
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: System ()
Version: master
Hardware: All All
: --- normal
Target Milestone: Untriaged
Assignee: Martin Baulig
URL:
Depends on:
Blocks:
 
Reported: 2011-12-06 11:00 UTC by Yves Bastide
Modified: 2012-06-19 21:07 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Possible fix and testcases (1.47 KB, patch)
2011-12-06 11:00 UTC, Yves Bastide
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Yves Bastide 2011-12-06 11:00:59 UTC
Created attachment 1001 [details]
Possible fix and testcases

Expected result:

csharp> new Uri("http://3.141592653589793238462643383279502884197169399375105820974944592.com/");
http://3.141592653589793238462643383279502884197169399375105820974944592.com/

Actual result:

csharp> new Uri("http://3.141592653589793238462643383279502884197169399375105820974944592.com/");
System.UriFormatException: Invalid URI: The hostname could not be parsed.
  at System.Uri.Parse (UriKind kind, System.String uriString) [0x00000] in <filename unknown>:0 
  at System.Uri.ParseUri (UriKind kind) [0x00000] in <filename unknown>:0 
  at System.Uri..ctor (System.String uriString, Boolean dontEscape) [0x00000] in <filename unknown>:0 
  at System.Uri..ctor (System.String uriString) [0x00000] in <filename unknown>:0 
  at Class1.Host (System.Object& $retval) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.Evaluator.Evaluate (System.String input, System.Object& result, System.Boolean& result_set) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.Gui.Shell.Evaluate (System.String s) [0x00000] in <filename unknown>:0

Bug analysis:

The part ("label") 141592653589793238462643383279502884197169399375105820974944592 is 63 chars long; however, System.Uri:IsDomainAddress includes the preceding dot.

Attached are a fix and some unit tests.

Regards,

yves
Comment 1 Martin Baulig 2012-06-19 21:07:42 UTC
Fixed; commit 330f0eb.

FIXME: We still violate RFC 2181 by not checking the total length of the hostname (maximum 255 bytes), but .NET doesn't check it either.