Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Mono.WebServer.Apache: fix handling of ipv6 addresses

Detect whether or not host is an ipv6 address with or without port number and parse accordingly.
Fixes a bug where if connecting to a webserver by entering ipv6 address manually an exception would be thrown by Int32.Parse.
  • Loading branch information...
commit 1b5d56c4f0e8934dd53cccf3ce9dfb998932ff33 1 parent b03b249
@ghinriksson ghinriksson authored
Showing with 23 additions and 9 deletions.
  1. +23 −9 src/Mono.WebServer.Apache/ModMonoWorker.cs
View
32 src/Mono.WebServer.Apache/ModMonoWorker.cs
@@ -191,15 +191,29 @@ void InnerRun (object state)
string vhost = rr.Request.GetRequestHeader ("Host");
int port = -1;
- if (vhost != null) {
- int colon = vhost.IndexOf (':');
- if (colon != -1) {
- port = Int32.Parse (vhost.Substring (colon + 1));
- vhost = vhost.Substring (0, colon);
- } else {
- port = 80;
- }
- }
+ if (vhost != null) {
+ int lead = vhost.IndexOf('[');
+ int follow = lead >= 0 ? vhost.IndexOf(']') : -1;
+ if (follow > lead) {
+ //ipv6 address
+ int colon = vhost.IndexOf("]:", StringComparison.Ordinal);
+ if (colon != -1) {
+ Int32.TryParse (vhost.Substring (colon + 2), out port);
+ vhost = vhost.Substring(0, colon + 1);
+ }
+ } else {
+ //ipv4 or hostname
+ int colon = vhost.IndexOf (':');
+ if (colon != -1) {
+ Int32.TryParse (vhost.Substring (colon + 1), out port);
+ vhost = vhost.Substring (0, colon);
+ }
+ }
+ if (port <= 0 || port > 65535) {
+ //No port specified, Int32.TryParse failed or invalid port number
+ port = 80;
+ }
+ }
string vServerName = rr.Request.GetVirtualServerName ();
if (vServerName == null)
Please sign in to comment.
Something went wrong with that request. Please try again.