From 37f28b411937eb6ab13b787beb2ebcb3fe8e3f00 Mon Sep 17 00:00:00 2001 From: Davide Beatrici Date: Tue, 19 May 2020 04:53:38 +0200 Subject: [PATCH] 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. --- src/Cedar/Command.c | 10 +++++----- src/Cedar/Command.h | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Cedar/Command.c b/src/Cedar/Command.c index ff5df3ed..d033339a 100644 --- a/src/Cedar/Command.c +++ b/src/Cedar/Command.c @@ -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) { diff --git a/src/Cedar/Command.h b/src/Cedar/Command.h index 94345670..55a71718 100644 --- a/src/Cedar/Command.h +++ b/src/Cedar/Command.h @@ -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);