Modified WebSocketServerBase.cs to validate range of port number
This commit is contained in:
parent
9daaa33111
commit
c2d480060c
@ -1538,8 +1538,13 @@ namespace WebSocketSharp
|
|||||||
var port = uri.Port;
|
var port = uri.Port;
|
||||||
if (port > 0)
|
if (port > 0)
|
||||||
{
|
{
|
||||||
if ((scheme == "ws" && port == 443) ||
|
if (port > 65535)
|
||||||
(scheme == "wss" && port == 80))
|
{
|
||||||
|
message = "Invalid port number: " + port;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((scheme == "ws" && port == 443) || (scheme == "wss" && port == 80))
|
||||||
{
|
{
|
||||||
message = String.Format ("Invalid pair of scheme and port: {0}, {1}", scheme, port);
|
message = String.Format ("Invalid pair of scheme and port: {0}, {1}", scheme, port);
|
||||||
return false;
|
return false;
|
||||||
|
@ -106,12 +106,13 @@ namespace WebSocketSharp.Server
|
|||||||
if (!port.IsPortNumber ())
|
if (!port.IsPortNumber ())
|
||||||
throw new ArgumentOutOfRangeException ("port", "Invalid port number: " + port);
|
throw new ArgumentOutOfRangeException ("port", "Invalid port number: " + port);
|
||||||
|
|
||||||
if (port == 80 && secure || port == 443 && !secure)
|
if ((port == 80 && secure) || (port == 443 && !secure))
|
||||||
throw new ArgumentException (String.Format (
|
throw new ArgumentException (String.Format (
|
||||||
"Invalid pair of 'port' and 'secure': {0}, {1}", port, secure));
|
"Invalid pair of 'port' and 'secure': {0}, {1}", port, secure));
|
||||||
|
|
||||||
_port = port;
|
_port = port;
|
||||||
_secure = secure;
|
_secure = secure;
|
||||||
|
|
||||||
init ();
|
init ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,6 +135,9 @@ namespace WebSocketSharp.Server
|
|||||||
/// <exception cref="ArgumentNullException">
|
/// <exception cref="ArgumentNullException">
|
||||||
/// Either <paramref name="address"/> or <paramref name="absPath"/> is <see langword="null"/>.
|
/// Either <paramref name="address"/> or <paramref name="absPath"/> is <see langword="null"/>.
|
||||||
/// </exception>
|
/// </exception>
|
||||||
|
/// <exception cref="ArgumentOutOfRangeException">
|
||||||
|
/// <paramref name="port"/> is 0 or less, or 65536 or greater.
|
||||||
|
/// </exception>
|
||||||
/// <exception cref="ArgumentException">
|
/// <exception cref="ArgumentException">
|
||||||
/// <para>
|
/// <para>
|
||||||
/// <paramref name="absPath"/> is invalid.
|
/// <paramref name="absPath"/> is invalid.
|
||||||
@ -154,20 +157,19 @@ namespace WebSocketSharp.Server
|
|||||||
if (absPath == null)
|
if (absPath == null)
|
||||||
throw new ArgumentNullException ("absPath");
|
throw new ArgumentNullException ("absPath");
|
||||||
|
|
||||||
|
if (!port.IsPortNumber ())
|
||||||
|
throw new ArgumentOutOfRangeException ("port", "Invalid port number: " + port);
|
||||||
|
|
||||||
string msg;
|
string msg;
|
||||||
if (!absPath.IsValidAbsolutePath (out msg))
|
if (!absPath.IsValidAbsolutePath (out msg))
|
||||||
throw new ArgumentException (msg, "absPath");
|
throw new ArgumentException (msg, "absPath");
|
||||||
|
|
||||||
if ((port == 80 && secure) ||
|
if ((port == 80 && secure) || (port == 443 && !secure))
|
||||||
(port == 443 && !secure))
|
throw new ArgumentException (String.Format (
|
||||||
{
|
"Invalid pair of 'port' and 'secure': {0}, {1}", port, secure));
|
||||||
msg = String.Format (
|
|
||||||
"Invalid pair of 'port' and 'secure': {0}, {1}", port, secure);
|
|
||||||
throw new ArgumentException (msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
_address = address;
|
_address = address;
|
||||||
_port = port > 0 ? port : secure ? 443 : 80;
|
_port = port;
|
||||||
_uri = absPath.ToUri ();
|
_uri = absPath.ToUri ();
|
||||||
_secure = secure;
|
_secure = secure;
|
||||||
|
|
||||||
@ -322,8 +324,9 @@ namespace WebSocketSharp.Server
|
|||||||
|
|
||||||
_uri = uri;
|
_uri = uri;
|
||||||
_address = addrs [0];
|
_address = addrs [0];
|
||||||
|
_port = port;
|
||||||
_secure = scheme == "wss" ? true : false;
|
_secure = scheme == "wss" ? true : false;
|
||||||
_port = port > 0 ? port : _secure ? 443 : 80;
|
|
||||||
init ();
|
init ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user