1
0
mirror of https://github.com/SoftEtherVPN/SoftEtherVPN.git synced 2024-09-18 01:33:00 +03:00

Cedar/Command: add "limit_range" parameter to StrToPortList()

Originally, StrToPortList() returned NULL when it encountered a number equal to 0 or higher than 65535.

This commit adds a new parameter to the function called "limit_range":

- When its value is true, the function retains the original behavior.
- When its value is false, the function doesn't check whether the number is in the network port number range (1-65535).

The change is required because the command to set the UDP ports will allow to remove all ports by specifying "0" as the port number.
This commit is contained in:
Davide Beatrici 2020-05-19 04:53:38 +02:00
parent f1cb86d979
commit 37f28b4119
2 changed files with 6 additions and 6 deletions

View File

@ -7880,7 +7880,7 @@ bool CmdEvalIp(CONSOLE *c, wchar_t *str, void *param)
}
// Convert a string to port list
LIST *StrToPortList(char *str)
LIST *StrToPortList(char *str, bool limit_range)
{
LIST *o;
TOKEN_LIST *t;
@ -7915,7 +7915,7 @@ LIST *StrToPortList(char *str)
return NULL;
}
n = ToInt(s);
if (n == 0 || n >= 65536)
if (limit_range && (n == 0 || n >= 65536))
{
ReleaseList(o);
FreeToken(t);
@ -7958,7 +7958,7 @@ UINT PsClusterSettingMember(CONSOLE *c, char *cmd_name, wchar_t *str, void *para
// "name", prompt_proc, prompt_param, eval_proc, eval_param
{"[server:port]", CmdPrompt, _UU("CMD_ClusterSettingMember_Prompt_HOST_1"), CmdEvalHostAndPort, NULL},
{"IP", PsClusterSettingMemberPromptIp, NULL, CmdEvalIp, NULL},
{"PORTS", PsClusterSettingMemberPromptPorts, NULL, CmdEvalPortList, NULL},
{"PORTS", PsClusterSettingMemberPromptPorts, NULL, CmdEvalPortList, (void *)true},
{"PASSWORD", CmdPromptChoosePassword, NULL, NULL, NULL},
{"WEIGHT", NULL, NULL, NULL, NULL},
};
@ -7997,7 +7997,7 @@ UINT PsClusterSettingMember(CONSOLE *c, char *cmd_name, wchar_t *str, void *para
ports_str = GetParamStr(o, "PORTS");
ports = StrToPortList(ports_str);
ports = StrToPortList(ports_str, true);
t.NumPort = LIST_NUM(ports);
t.Ports = ZeroMalloc(sizeof(UINT) * t.NumPort);
@ -8044,7 +8044,7 @@ bool CmdEvalPortList(CONSOLE *c, wchar_t *str, void *param)
s = CopyUniToStr(str);
o = StrToPortList(s);
o = StrToPortList(s, (bool)param);
if (o != NULL)
{

View File

@ -227,7 +227,7 @@ char *CmdPasswordPrompt(CONSOLE *c);
bool CmdEvalIp(CONSOLE *c, wchar_t *str, void *param);
wchar_t *PsClusterSettingMemberPromptIp(CONSOLE *c, void *param);
bool CmdEvalHostAndPort(CONSOLE *c, wchar_t *str, void *param);
LIST *StrToPortList(char *str);
LIST *StrToPortList(char *str, bool limit_range);
bool CmdEvalPortList(CONSOLE *c, wchar_t *str, void *param);
wchar_t *PsClusterSettingMemberPromptPorts(CONSOLE *c, void *param);
K *CmdLoadKey(CONSOLE *c, wchar_t *filename);