Fix: '-' sign incorrectly parsed in hostname ACL, bandlim race condition on configuration reload

This commit is contained in:
Vladimir Dubrovin 2021-04-15 12:26:34 +03:00
parent ef3453f119
commit 0efea92980
2 changed files with 29 additions and 2 deletions

10
.gitignore vendored
View File

@ -11,6 +11,16 @@
*.lib *.lib
*.key *.key
*.pem *.pem
*.so
bin/3proxy
bin/proxy
bin/socks
bin/tcppm
bin/udppm
bin/pop3p
bin/smtpp
bin/ftppr
bin/mycrypt
bin64/ bin64/
dll/ dll/
tmp/ tmp/

View File

@ -691,12 +691,19 @@ int scanipl(char *arg, struct iplist *dst){
#endif #endif
char * slash, *dash; char * slash, *dash;
int masklen, addrlen; int masklen, addrlen;
int res;
if((slash = strchr((char *)arg, '/'))) *slash = 0; if((slash = strchr((char *)arg, '/'))) *slash = 0;
if((dash = strchr((char *)arg,'-'))) *dash = 0; if((dash = strchr((char *)arg,'-'))) *dash = 0;
if(afdetect(arg) == -1) return 1; if(afdetect(arg) == -1) {
if(!getip46(46, arg, (struct sockaddr *)&sa)) return 1; if(slash)*slash = '/';
if(dash)*dash = '-';
return 1;
}
res = getip46(46, arg, (struct sockaddr *)&sa);
if(dash)*dash = '-';
if(!res) return 1;
memcpy(&dst->ip_from, SAADDR(&sa), SAADDRLEN(&sa)); memcpy(&dst->ip_from, SAADDR(&sa), SAADDRLEN(&sa));
dst->family = *SAFAMILY(&sa); dst->family = *SAFAMILY(&sa);
if(dash){ if(dash){
@ -708,6 +715,7 @@ int scanipl(char *arg, struct iplist *dst){
} }
memcpy(&dst->ip_to, &dst->ip_from, SAADDRLEN(&sa)); memcpy(&dst->ip_to, &dst->ip_from, SAADDRLEN(&sa));
if(slash){ if(slash){
*slash = '/';
addrlen = SAADDRLEN(&sa); addrlen = SAADDRLEN(&sa);
masklen = atoi(slash+1); masklen = atoi(slash+1);
if(masklen < 0 || masklen > (addrlen*8)) return 4; if(masklen < 0 || masklen > (addrlen*8)) return 4;
@ -1052,6 +1060,7 @@ static int h_ace(int argc, char **argv){
case REDIRECT: case REDIRECT:
acl->chains = myalloc(sizeof(struct chain)); acl->chains = myalloc(sizeof(struct chain));
if(!acl->chains) { if(!acl->chains) {
freeacl(acl);
return(21); return(21);
} }
memset(acl->chains, 0, sizeof(struct chain)); memset(acl->chains, 0, sizeof(struct chain));
@ -1075,6 +1084,7 @@ static int h_ace(int argc, char **argv){
case NOCONNLIM: case NOCONNLIM:
ncl = myalloc(sizeof(struct connlim)); ncl = myalloc(sizeof(struct connlim));
if(!ncl) { if(!ncl) {
freeacl(acl);
return(21); return(21);
} }
memset(ncl, 0, sizeof(struct connlim)); memset(ncl, 0, sizeof(struct connlim));
@ -1101,6 +1111,7 @@ static int h_ace(int argc, char **argv){
nbl = myalloc(sizeof(struct bandlim)); nbl = myalloc(sizeof(struct bandlim));
if(!nbl) { if(!nbl) {
freeacl(acl);
return(21); return(21);
} }
memset(nbl, 0, sizeof(struct bandlim)); memset(nbl, 0, sizeof(struct bandlim));
@ -1108,6 +1119,8 @@ static int h_ace(int argc, char **argv){
if(acl->action == BANDLIM) { if(acl->action == BANDLIM) {
sscanf((char *)argv[1], "%u", &nbl->rate); sscanf((char *)argv[1], "%u", &nbl->rate);
if(nbl->rate < 300) { if(nbl->rate < 300) {
myfree(nbl);
freeacl(acl);
fprintf(stderr, "Wrong bandwidth specified, line %d\n", linenum); fprintf(stderr, "Wrong bandwidth specified, line %d\n", linenum);
return(4); return(4);
} }
@ -1148,6 +1161,7 @@ static int h_ace(int argc, char **argv){
if(!conf.trafcountfunc) conf.trafcountfunc = trafcountfunc; if(!conf.trafcountfunc) conf.trafcountfunc = trafcountfunc;
tl = myalloc(sizeof(struct trafcount)); tl = myalloc(sizeof(struct trafcount));
if(!tl) { if(!tl) {
freeacl(acl);
return(21); return(21);
} }
memset(tl, 0, sizeof(struct trafcount)); memset(tl, 0, sizeof(struct trafcount));
@ -1166,6 +1180,8 @@ static int h_ace(int argc, char **argv){
tl->type = getrotate(*argv[2]); tl->type = getrotate(*argv[2]);
tl->traflim64 = ((uint64_t)lim)*(1024*1024); tl->traflim64 = ((uint64_t)lim)*(1024*1024);
if(!tl->traflim64) { if(!tl->traflim64) {
myfree(tl);
freeacl(acl);
fprintf(stderr, "Wrong traffic limit specified, line %d\n", linenum); fprintf(stderr, "Wrong traffic limit specified, line %d\n", linenum);
return(6); return(6);
} }
@ -1686,6 +1702,7 @@ void freeconf(struct extparam *confp){
confp->bandlimiter = NULL; confp->bandlimiter = NULL;
confp->bandlimiterout = NULL; confp->bandlimiterout = NULL;
confp->bandlimfunc = NULL; confp->bandlimfunc = NULL;
confp->bandlimver++;
pthread_mutex_unlock(&bandlim_mutex); pthread_mutex_unlock(&bandlim_mutex);
pthread_mutex_lock(&connlim_mutex); pthread_mutex_lock(&connlim_mutex);
cl = confp->connlimiter; cl = confp->connlimiter;