- Fix my braino in the 220835, when I used strtok(). It isn't
applicable here, since modifies the string. Switch to strchr(). - Restore support for undocumented optional parameters of redir_port and redir_proto, that were disabled in 220835. - While here, change !isalpha() checks on optinal parameters for isdigit(). Submitted by: Alexander V. Chernikov <melifaro ipfw.ru> PR: kern/143653
This commit is contained in:
parent
f5f215e251
commit
ce97208218
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=223185
@ -315,14 +315,19 @@ static int
|
|||||||
estimate_redir_addr(int *ac, char ***av)
|
estimate_redir_addr(int *ac, char ***av)
|
||||||
{
|
{
|
||||||
size_t space = sizeof(struct cfg_redir);
|
size_t space = sizeof(struct cfg_redir);
|
||||||
char *sep;
|
char *sep = **av;
|
||||||
|
u_int c = 0;
|
||||||
|
|
||||||
if ((sep = strtok(**av, ",")) != NULL) {
|
while ((sep = strchr(sep, ',')) != NULL) {
|
||||||
space += sizeof(struct cfg_spool);
|
c++;
|
||||||
while ((sep = strtok(NULL, ",")) != NULL)
|
sep++;
|
||||||
space += sizeof(struct cfg_spool);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (c > 0)
|
||||||
|
c++;
|
||||||
|
|
||||||
|
space += c * sizeof(struct cfg_spool);
|
||||||
|
|
||||||
return (space);
|
return (space);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -370,14 +375,19 @@ static int
|
|||||||
estimate_redir_port(int *ac, char ***av)
|
estimate_redir_port(int *ac, char ***av)
|
||||||
{
|
{
|
||||||
size_t space = sizeof(struct cfg_redir);
|
size_t space = sizeof(struct cfg_redir);
|
||||||
char *sep;
|
char *sep = **av;
|
||||||
|
u_int c = 0;
|
||||||
|
|
||||||
if ((sep = strtok(**av, ",")) != NULL) {
|
while ((sep = strchr(sep, ',')) != NULL) {
|
||||||
space += sizeof(struct cfg_spool);
|
c++;
|
||||||
while ((sep = strtok(NULL, ",")) != NULL)
|
sep++;
|
||||||
space += sizeof(struct cfg_spool);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (c > 0)
|
||||||
|
c++;
|
||||||
|
|
||||||
|
space += c * sizeof(struct cfg_spool);
|
||||||
|
|
||||||
return (space);
|
return (space);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -465,10 +475,10 @@ setup_redir_port(char *buf, int *ac, char ***av)
|
|||||||
* Extract remote address and optionally port.
|
* Extract remote address and optionally port.
|
||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
* NB: isalpha(**av) => we've to check that next parameter is really an
|
* NB: isdigit(**av) => we've to check that next parameter is really an
|
||||||
* option for this redirect entry, else stop here processing arg[cv].
|
* option for this redirect entry, else stop here processing arg[cv].
|
||||||
*/
|
*/
|
||||||
if (*ac != 0 && !isalpha(***av)) {
|
if (*ac != 0 && isdigit(***av)) {
|
||||||
if ((sep = strchr(**av, ':')) != NULL) {
|
if ((sep = strchr(**av, ':')) != NULL) {
|
||||||
if (StrToAddrAndPortRange(**av, &r->raddr, protoName,
|
if (StrToAddrAndPortRange(**av, &r->raddr, protoName,
|
||||||
&portRange) != 0)
|
&portRange) != 0)
|
||||||
@ -584,7 +594,7 @@ setup_redir_proto(char *buf, int *ac, char ***av)
|
|||||||
r->raddr.s_addr = INADDR_ANY;
|
r->raddr.s_addr = INADDR_ANY;
|
||||||
} else {
|
} else {
|
||||||
/* see above in setup_redir_port() */
|
/* see above in setup_redir_port() */
|
||||||
if (!isalpha(***av)) {
|
if (isdigit(***av)) {
|
||||||
StrToAddr(**av, &r->paddr);
|
StrToAddr(**av, &r->paddr);
|
||||||
(*av)++; (*ac)--;
|
(*av)++; (*ac)--;
|
||||||
|
|
||||||
@ -592,7 +602,7 @@ setup_redir_proto(char *buf, int *ac, char ***av)
|
|||||||
* Extract optional remote address.
|
* Extract optional remote address.
|
||||||
*/
|
*/
|
||||||
/* see above in setup_redir_port() */
|
/* see above in setup_redir_port() */
|
||||||
if (*ac != 0 && !isalpha(***av)) {
|
if (*ac != 0 && isdigit(***av)) {
|
||||||
StrToAddr(**av, &r->raddr);
|
StrToAddr(**av, &r->raddr);
|
||||||
(*av)++; (*ac)--;
|
(*av)++; (*ac)--;
|
||||||
}
|
}
|
||||||
@ -774,6 +784,9 @@ ipfw_config_nat(int ac, char **av)
|
|||||||
av1++; ac1--;
|
av1++; ac1--;
|
||||||
len += estimate_redir_port(&ac1, &av1);
|
len += estimate_redir_port(&ac1, &av1);
|
||||||
av1 += 2; ac1 -= 2;
|
av1 += 2; ac1 -= 2;
|
||||||
|
/* Skip optional remoteIP/port */
|
||||||
|
if (ac1 != 0 && isdigit(**av1))
|
||||||
|
av1++; ac1--;
|
||||||
break;
|
break;
|
||||||
case TOK_REDIR_PROTO:
|
case TOK_REDIR_PROTO:
|
||||||
if (ac1 < 2)
|
if (ac1 < 2)
|
||||||
@ -781,6 +794,11 @@ ipfw_config_nat(int ac, char **av)
|
|||||||
"not enough arguments");
|
"not enough arguments");
|
||||||
len += sizeof(struct cfg_redir);
|
len += sizeof(struct cfg_redir);
|
||||||
av1 += 2; ac1 -= 2;
|
av1 += 2; ac1 -= 2;
|
||||||
|
/* Skip optional remoteIP/port */
|
||||||
|
if (ac1 != 0 && isdigit(**av1))
|
||||||
|
av1++; ac1--;
|
||||||
|
if (ac1 != 0 && isdigit(**av1))
|
||||||
|
av1++; ac1--;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
errx(EX_DATAERR, "unrecognised option ``%s''", av1[-1]);
|
errx(EX_DATAERR, "unrecognised option ``%s''", av1[-1]);
|
||||||
|
Loading…
Reference in New Issue
Block a user