[Network] Solve type mismatch in AllowPort().

Casting it to an int16_t was wrong and would preclude the check for high port
numbers (due to overflow).
This makes the type matching, but adds an explicit check to ensure the port
number passed in is within a valid range.
This commit is contained in:
Moonchild 2021-04-20 13:12:38 +00:00 committed by roytam1
commit 69597507db

View file

@ -1203,13 +1203,14 @@ nsIOService::SetConnectivityInternal(bool aConnectivity)
NS_IMETHODIMP
nsIOService::AllowPort(int32_t inPort, const char *scheme, bool *_retval)
{
int16_t port = inPort;
int32_t port = inPort;
if (port == -1) {
*_retval = true;
return NS_OK;
}
if (port == 0) {
// Ensure the port number is within a valid range
if (port <= 0 || port >= std::numeric_limits<uint16_t>::max()) {
*_retval = false;
return NS_OK;
}