nfqws,tpws: fix possible crashes or high memory usage if hostlist has duplicate hostnames

This commit is contained in:
bol-van
2025-08-08 11:35:13 +03:00
parent d6a8d1dc33
commit 56456c1e0c
3 changed files with 19 additions and 9 deletions

View File

@@ -534,3 +534,7 @@ nfqws: ts fooling
blockcheck: test ts fooling
blockcheck: auto enable tcp timestamps in windows
tpws,nfqws: special handling of IP-like hostnames. strip :port from hostname:port
v71.4
nfqws,tpws: fix possible crashes or high memory usage if hostlist has duplicate hostnames

View File

@@ -12,7 +12,7 @@
HASH_DEL(*ppool, elem); \
free(elem); \
}
#define ADD_STR_POOL(etype, ppool, keystr, keystr_len) \
etype *elem; \
if (!(elem = (etype*)malloc(sizeof(etype)))) \
@@ -25,7 +25,7 @@
memcpy(elem->str, keystr, keystr_len); \
elem->str[keystr_len] = 0; \
oom = false; \
HASH_ADD_KEYPTR(hh, *ppool, elem->str, strlen(elem->str), elem); \
HASH_ADD_KEYPTR(hh, *ppool, elem->str, keystr_len, elem); \
if (oom) \
{ \
free(elem->str); \
@@ -33,9 +33,12 @@
return false; \
}
#define ADD_HOSTLIST_POOL(etype, ppool, keystr, keystr_len, flg) \
ADD_STR_POOL(etype,ppool,keystr,keystr_len); \
elem->flags = flg;
etype *elem_find; \
HASH_FIND(hh, *ppool, keystr, keystr_len, elem_find); \
if (!elem_find) { \
ADD_STR_POOL(etype,ppool,keystr,keystr_len); \
elem->flags = flg; \
}
#undef uthash_nonfatal_oom
#define uthash_nonfatal_oom(elt) ut_oom_recover(elt)

View File

@@ -25,7 +25,7 @@
memcpy(elem->str, keystr, keystr_len); \
elem->str[keystr_len] = 0; \
oom = false; \
HASH_ADD_KEYPTR(hh, *ppool, elem->str, strlen(elem->str), elem); \
HASH_ADD_KEYPTR(hh, *ppool, elem->str, keystr_len, elem); \
if (oom) \
{ \
free(elem->str); \
@@ -33,9 +33,12 @@
return false; \
}
#define ADD_HOSTLIST_POOL(etype, ppool, keystr, keystr_len, flg) \
ADD_STR_POOL(etype,ppool,keystr,keystr_len); \
elem->flags = flg;
etype *elem_find; \
HASH_FIND(hh, *ppool, keystr, keystr_len, elem_find); \
if (!elem_find) { \
ADD_STR_POOL(etype,ppool,keystr,keystr_len); \
elem->flags = flg; \
}
#undef uthash_nonfatal_oom
#define uthash_nonfatal_oom(elt) ut_oom_recover(elt)