Better error checking when creating hyperlinks: a) Reject invalid strings; b) Default port is 80, not 0

The change of default port may fix http://opensimulator.org/mantis/view.php?id=7108 , where a user was able to create a Hyperlink to OSGrid from inside OSGrid.
0.8.0.3
Oren Hurvitz 2014-04-13 11:51:47 +03:00
parent c8914d22eb
commit e1dd228f18
1 changed files with 36 additions and 17 deletions

View File

@ -202,18 +202,27 @@ namespace OpenSim.Services.GridService
if (!mapName.StartsWith("http")) if (!mapName.StartsWith("http"))
{ {
string host = "127.0.0.1"; // Formats: grid.example.com:8002:region name
string portstr; // grid.example.com:region name
// grid.example.com
string host;
uint port = 80;
string regionName = ""; string regionName = "";
uint port = 0;
string[] parts = mapName.Split(new char[] { ':' }); string[] parts = mapName.Split(new char[] { ':' });
if (parts.Length >= 1)
if (parts.Length == 0)
{ {
host = parts[0]; reason = "Wrong format for link-region";
return null;
} }
host = parts[0];
if (parts.Length >= 2) if (parts.Length >= 2)
{ {
portstr = parts[1]; string portstr = parts[1];
//m_log.Debug("-- port = " + portstr); //m_log.Debug("-- port = " + portstr);
if (!UInt32.TryParse(portstr, out port)) if (!UInt32.TryParse(portstr, out port))
regionName = parts[1]; regionName = parts[1];
@ -234,13 +243,22 @@ namespace OpenSim.Services.GridService
} }
else else
{ {
string[] parts = mapName.Split(new char[] {' '}); // Formats: http://grid.example.com region name
string regionName = String.Empty; // http://grid.example.com "region name"
if (parts.Length > 1)
string regionName;
string[] parts = mapName.Split(new char[] { ' ' });
if (parts.Length < 2)
{ {
regionName = mapName.Substring(parts[0].Length + 1); reason = "Wrong format for link-region";
regionName = regionName.Trim(new char[] {'"'}); return null;
} }
regionName = mapName.Substring(parts[0].Length + 1);
regionName = regionName.Trim(new char[] {'"'});
if (TryCreateLink(scopeID, xloc, yloc, regionName, 0, null, parts[0], ownerID, out regInfo, out reason)) if (TryCreateLink(scopeID, xloc, yloc, regionName, 0, null, parts[0], ownerID, out regInfo, out reason))
{ {
regInfo.RegionName = mapName; regInfo.RegionName = mapName;
@ -258,7 +276,7 @@ namespace OpenSim.Services.GridService
public bool TryCreateLink(UUID scopeID, int xloc, int yloc, string remoteRegionName, uint externalPort, string externalHostName, string serverURI, UUID ownerID, out GridRegion regInfo, out string reason) public bool TryCreateLink(UUID scopeID, int xloc, int yloc, string remoteRegionName, uint externalPort, string externalHostName, string serverURI, UUID ownerID, out GridRegion regInfo, out string reason)
{ {
m_log.DebugFormat("[HYPERGRID LINKER]: Link to {0} {1}, in {2}-{3}", m_log.InfoFormat("[HYPERGRID LINKER]: Link to {0} {1}, in {2}-{3}",
((serverURI == null) ? (externalHostName + ":" + externalPort) : serverURI), ((serverURI == null) ? (externalHostName + ":" + externalPort) : serverURI),
remoteRegionName, Util.WorldToRegionLoc((uint)xloc), Util.WorldToRegionLoc((uint)yloc)); remoteRegionName, Util.WorldToRegionLoc((uint)xloc), Util.WorldToRegionLoc((uint)yloc));
@ -266,15 +284,15 @@ namespace OpenSim.Services.GridService
Uri uri = null; Uri uri = null;
regInfo = new GridRegion(); regInfo = new GridRegion();
if ( externalPort > 0) if (externalPort > 0)
regInfo.HttpPort = externalPort; regInfo.HttpPort = externalPort;
else else
regInfo.HttpPort = 0; regInfo.HttpPort = 80;
if ( externalHostName != null) if (externalHostName != null)
regInfo.ExternalHostName = externalHostName; regInfo.ExternalHostName = externalHostName;
else else
regInfo.ExternalHostName = "0.0.0.0"; regInfo.ExternalHostName = "0.0.0.0";
if ( serverURI != null) if (serverURI != null)
{ {
regInfo.ServerURI = serverURI; regInfo.ServerURI = serverURI;
try try
@ -286,7 +304,7 @@ namespace OpenSim.Services.GridService
catch {} catch {}
} }
if ( remoteRegionName != string.Empty ) if (remoteRegionName != string.Empty)
regInfo.RegionName = remoteRegionName; regInfo.RegionName = remoteRegionName;
regInfo.RegionLocX = xloc; regInfo.RegionLocX = xloc;
@ -299,6 +317,7 @@ namespace OpenSim.Services.GridService
{ {
if (regInfo.ExternalHostName == m_ThisGatekeeperURI.Host && regInfo.HttpPort == m_ThisGatekeeperURI.Port) if (regInfo.ExternalHostName == m_ThisGatekeeperURI.Host && regInfo.HttpPort == m_ThisGatekeeperURI.Port)
{ {
m_log.InfoFormat("[HYPERGRID LINKER]: Cannot hyperlink to regions on the same grid");
reason = "Cannot hyperlink to regions on the same grid"; reason = "Cannot hyperlink to regions on the same grid";
return false; return false;
} }