Template
1
0
mirror of https://github.com/bol-van/zapret2.git synced 2026-03-14 06:13:09 +00:00

nfqws2: check hostlist/ipset file is readable before destroying in-memory copy

This commit is contained in:
bol-van
2026-01-19 11:46:21 +03:00
parent 577d9e6aba
commit 33b1e81041
4 changed files with 27 additions and 5 deletions

View File

@@ -113,10 +113,18 @@ static bool LoadHostList(struct hostlist_file *hfile)
{
// stat() error
DLOG_PERROR("file_mod_signature");
DLOG_ERR("cannot access hostlist file '%s'. in-memory content remains unchanged.\n",hfile->filename);
return true;
goto unchanged;
}
if (FILE_MOD_COMPARE(&hfile->mod_sig,&fsig)) return true; // up to date
// check if it's readable. do not destroy in-memory copy if not
if (!file_open_test(hfile->filename, O_RDONLY))
{
DLOG_PERROR("file_open_test");
goto unchanged;
}
// don't want to keep backup copy in memory - it will require *2 RAM. Problem on low-ram devices. It's better to fail hostlist read than have OOM.
// if a file can be opened there're few chances it can't be read. fs corruption, disk error, deleted or made inaccessible between 2 syscals ?
// it's all hypotetically possible but very unlikely. but OOM is much more real problem on an embedded device if list is large enough
HostlistPoolDestroy(&hfile->hostlist);
if (!AppendHostList(&hfile->hostlist, hfile->filename))
{
@@ -126,6 +134,9 @@ static bool LoadHostList(struct hostlist_file *hfile)
hfile->mod_sig=fsig;
}
return true;
unchanged:
DLOG_ERR("cannot access hostlist file '%s'. in-memory content remains unchanged.\n",hfile->filename);
return true;
}
static bool LoadHostLists(struct hostlist_files_head *list)
{