Fix OpenVPN server port validation to disallow "0". 0 is still OK for client port, which is the same meaning as blank/empty. Fixes #7565

This commit is contained in:
jim-p 2017-05-22 12:35:17 -04:00
parent bc3669e4e8
commit 39fed38653
2 changed files with 7 additions and 4 deletions

View File

@ -509,10 +509,13 @@ function openvpn_validate_host($value, $name) {
return false;
}
function openvpn_validate_port($value, $name) {
function openvpn_validate_port($value, $name, $first_port = 0) {
$value = trim($value);
if (empty($value) || !is_numeric($value) || $value < 0 || ($value > 65535)) {
return sprintf(gettext("The field '%s' must contain a valid port, ranging from 0 to 65535."), $name);
if (!is_numeric($first_port)) {
$first_port = 0;
}
if (empty($value) || !is_numeric($value) || $value < $first_port || ($value > 65535)) {
return sprintf(gettext("The field '%s' must contain a valid port, ranging from {$first_port} to 65535."), $name);
}
return false;
}

View File

@ -295,7 +295,7 @@ if ($_POST['save']) {
}
/* input validation */
if ($result = openvpn_validate_port($pconfig['local_port'], 'Local port')) {
if ($result = openvpn_validate_port($pconfig['local_port'], 'Local port', 1)) {
$input_errors[] = $result;
}