mirror of
https://github.com/bol-van/zapret.git
synced 2024-11-29 21:40:52 +03:00
tpws,nfqws: fix 100% cpu hang on gzipped hostlist with comments
This commit is contained in:
parent
f32df7d701
commit
baca5a184d
@ -4,17 +4,27 @@
|
|||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
|
|
||||||
// inplace tolower() and add to pool
|
// inplace tolower() and add to pool
|
||||||
static bool addpool(strpool **hostlist, char **s, const char *end)
|
static bool addpool(strpool **hostlist, char **s, const char *end, int *ct)
|
||||||
{
|
{
|
||||||
char *p;
|
char *p=*s;
|
||||||
|
|
||||||
// advance until eol lowering all chars
|
// comment line
|
||||||
for (p = *s; p<end && *p && *p!='\r' && *p != '\n'; p++) *p=tolower(*p);
|
if ( *p == '#' || *p == ';' || *p == '/' || *p == '\r' || *p == '\n')
|
||||||
if (!StrPoolAddStrLen(hostlist, *s, p-*s))
|
|
||||||
{
|
{
|
||||||
StrPoolDestroy(hostlist);
|
// advance until eol
|
||||||
*hostlist = NULL;
|
for (; p<end && *p && *p!='\r' && *p != '\n'; p++);
|
||||||
return false;
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// advance until eol lowering all chars
|
||||||
|
for (; p<end && *p && *p!='\r' && *p != '\n'; p++) *p=tolower(*p);
|
||||||
|
if (!StrPoolAddStrLen(hostlist, *s, p-*s))
|
||||||
|
{
|
||||||
|
StrPoolDestroy(hostlist);
|
||||||
|
*hostlist = NULL;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
(*ct)++;
|
||||||
}
|
}
|
||||||
// advance to the next line
|
// advance to the next line
|
||||||
for (; p<end && (!*p || *p=='\r' || *p=='\n') ; p++);
|
for (; p<end && (!*p || *p=='\r' || *p=='\n') ; p++);
|
||||||
@ -22,7 +32,7 @@ static bool addpool(strpool **hostlist, char **s, const char *end)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AppendHostList(strpool **hostlist, char *filename)
|
bool AppendHostList(strpool **hostlist, const char *filename)
|
||||||
{
|
{
|
||||||
char *p, *e, s[256], *zbuf;
|
char *p, *e, s[256], *zbuf;
|
||||||
size_t zsize;
|
size_t zsize;
|
||||||
@ -50,14 +60,12 @@ bool AppendHostList(strpool **hostlist, char *filename)
|
|||||||
e = zbuf + zsize;
|
e = zbuf + zsize;
|
||||||
while(p<e)
|
while(p<e)
|
||||||
{
|
{
|
||||||
if ( *p == '#' || *p == ';' || *p == '/' || *p == '\n' ) continue;
|
if (!addpool(hostlist,&p,e,&ct))
|
||||||
if (!addpool(hostlist,&p,e))
|
|
||||||
{
|
{
|
||||||
DLOG_ERR("Not enough memory to store host list : %s\n", filename);
|
DLOG_ERR("Not enough memory to store host list : %s\n", filename);
|
||||||
free(zbuf);
|
free(zbuf);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
ct++;
|
|
||||||
}
|
}
|
||||||
free(zbuf);
|
free(zbuf);
|
||||||
}
|
}
|
||||||
@ -71,17 +79,15 @@ bool AppendHostList(strpool **hostlist, char *filename)
|
|||||||
{
|
{
|
||||||
DLOG_CONDUP("loading plain text list\n");
|
DLOG_CONDUP("loading plain text list\n");
|
||||||
|
|
||||||
while (fgets(s, 256, F))
|
while (fgets(s, sizeof(s), F))
|
||||||
{
|
{
|
||||||
p = s;
|
p = s;
|
||||||
if ( *p == '#' || *p == ';' || *p == '/' || *p == '\n' ) continue;
|
if (!addpool(hostlist,&p,p+strlen(p),&ct))
|
||||||
if (!addpool(hostlist,&p,p+strlen(p)))
|
|
||||||
{
|
{
|
||||||
DLOG_ERR("Not enough memory to store host list : %s\n", filename);
|
DLOG_ERR("Not enough memory to store host list : %s\n", filename);
|
||||||
fclose(F);
|
fclose(F);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
ct++;
|
|
||||||
}
|
}
|
||||||
fclose(F);
|
fclose(F);
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
#include "pools.h"
|
#include "pools.h"
|
||||||
#include "params.h"
|
#include "params.h"
|
||||||
|
|
||||||
bool AppendHostList(strpool **hostlist, char *filename);
|
bool AppendHostList(strpool **hostlist, const char *filename);
|
||||||
bool LoadHostLists(strpool **hostlist, struct str_list_head *file_list);
|
bool LoadHostLists(strpool **hostlist, struct str_list_head *file_list);
|
||||||
bool LoadIncludeHostLists();
|
bool LoadIncludeHostLists();
|
||||||
bool LoadExcludeHostLists();
|
bool LoadExcludeHostLists();
|
||||||
|
@ -5,17 +5,27 @@
|
|||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
|
|
||||||
// inplace tolower() and add to pool
|
// inplace tolower() and add to pool
|
||||||
static bool addpool(strpool **hostlist, char **s, const char *end)
|
static bool addpool(strpool **hostlist, char **s, const char *end, int *ct)
|
||||||
{
|
{
|
||||||
char *p;
|
char *p=*s;
|
||||||
|
|
||||||
// advance until eol lowering all chars
|
// comment line
|
||||||
for (p = *s; p<end && *p && *p!='\r' && *p != '\n'; p++) *p=tolower(*p);
|
if ( *p == '#' || *p == ';' || *p == '/' || *p == '\r' || *p == '\n')
|
||||||
if (!StrPoolAddStrLen(hostlist, *s, p-*s))
|
|
||||||
{
|
{
|
||||||
StrPoolDestroy(hostlist);
|
// advance until eol
|
||||||
*hostlist = NULL;
|
for (; p<end && *p && *p!='\r' && *p != '\n'; p++);
|
||||||
return false;
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// advance until eol lowering all chars
|
||||||
|
for (; p<end && *p && *p!='\r' && *p != '\n'; p++) *p=tolower(*p);
|
||||||
|
if (!StrPoolAddStrLen(hostlist, *s, p-*s))
|
||||||
|
{
|
||||||
|
StrPoolDestroy(hostlist);
|
||||||
|
*hostlist = NULL;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
(*ct)++;
|
||||||
}
|
}
|
||||||
// advance to the next line
|
// advance to the next line
|
||||||
for (; p<end && (!*p || *p=='\r' || *p=='\n') ; p++);
|
for (; p<end && (!*p || *p=='\r' || *p=='\n') ; p++);
|
||||||
@ -23,7 +33,7 @@ static bool addpool(strpool **hostlist, char **s, const char *end)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AppendHostList(strpool **hostlist, char *filename)
|
bool AppendHostList(strpool **hostlist, const char *filename)
|
||||||
{
|
{
|
||||||
char *p, *e, s[256], *zbuf;
|
char *p, *e, s[256], *zbuf;
|
||||||
size_t zsize;
|
size_t zsize;
|
||||||
@ -51,14 +61,12 @@ bool AppendHostList(strpool **hostlist, char *filename)
|
|||||||
e = zbuf + zsize;
|
e = zbuf + zsize;
|
||||||
while(p<e)
|
while(p<e)
|
||||||
{
|
{
|
||||||
if ( *p == '#' || *p == ';' || *p == '/' || *p == '\n' ) continue;
|
if (!addpool(hostlist,&p,e,&ct))
|
||||||
if (!addpool(hostlist,&p,e))
|
|
||||||
{
|
{
|
||||||
DLOG_ERR("Not enough memory to store host list : %s\n", filename);
|
DLOG_ERR("Not enough memory to store host list : %s\n", filename);
|
||||||
free(zbuf);
|
free(zbuf);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
ct++;
|
|
||||||
}
|
}
|
||||||
free(zbuf);
|
free(zbuf);
|
||||||
}
|
}
|
||||||
@ -72,17 +80,15 @@ bool AppendHostList(strpool **hostlist, char *filename)
|
|||||||
{
|
{
|
||||||
DLOG_CONDUP("loading plain text list\n");
|
DLOG_CONDUP("loading plain text list\n");
|
||||||
|
|
||||||
while (fgets(s, 256, F))
|
while (fgets(s, sizeof(s), F))
|
||||||
{
|
{
|
||||||
p = s;
|
p = s;
|
||||||
if ( *p == '#' || *p == ';' || *p == '/' || *p == '\n' ) continue;
|
if (!addpool(hostlist,&p,p+strlen(p),&ct))
|
||||||
if (!addpool(hostlist,&p,p+strlen(p)))
|
|
||||||
{
|
{
|
||||||
DLOG_ERR("Not enough memory to store host list : %s\n", filename);
|
DLOG_ERR("Not enough memory to store host list : %s\n", filename);
|
||||||
fclose(F);
|
fclose(F);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
ct++;
|
|
||||||
}
|
}
|
||||||
fclose(F);
|
fclose(F);
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
#include "pools.h"
|
#include "pools.h"
|
||||||
#include "params.h"
|
#include "params.h"
|
||||||
|
|
||||||
bool AppendHostList(strpool **hostlist, char *filename);
|
bool AppendHostList(strpool **hostlist, const char *filename);
|
||||||
bool LoadHostLists(strpool **hostlist, struct str_list_head *file_list);
|
bool LoadHostLists(strpool **hostlist, struct str_list_head *file_list);
|
||||||
bool LoadIncludeHostLists();
|
bool LoadIncludeHostLists();
|
||||||
bool LoadExcludeHostLists();
|
bool LoadExcludeHostLists();
|
||||||
|
Loading…
Reference in New Issue
Block a user