mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-22 07:31:57 +00:00
CaresPTRResolver small safety improvement
Previous to #40769, only `hostent::h_aliases` was being accessed. After that PR got merged, `hostent::h_name` started being accessed as well. This PR moves the first `hostent::h_aliases != nullptr` check that could prevent `hostent::h_name` from being accessed. During debugging, I observed that even when there are not aliases, `hostent::h_aliases` is not null. That's why it hasn't caused any problems, but proposing this change to be on the safe side.
This commit is contained in:
parent
29ac78a92b
commit
fb42afbbac
@ -15,8 +15,8 @@ namespace DB
|
|||||||
|
|
||||||
static void callback(void * arg, int status, int, struct hostent * host)
|
static void callback(void * arg, int status, int, struct hostent * host)
|
||||||
{
|
{
|
||||||
auto * ptr_records = reinterpret_cast<std::unordered_set<std::string>*>(arg);
|
auto * ptr_records = static_cast<std::unordered_set<std::string>*>(arg);
|
||||||
if (status == ARES_SUCCESS && host->h_aliases)
|
if (ptr_records && status == ARES_SUCCESS)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* In some cases (e.g /etc/hosts), hostent::h_name is filled and hostent::h_aliases is empty.
|
* In some cases (e.g /etc/hosts), hostent::h_name is filled and hostent::h_aliases is empty.
|
||||||
@ -28,11 +28,14 @@ namespace DB
|
|||||||
ptr_records->insert(ptr_record);
|
ptr_records->insert(ptr_record);
|
||||||
}
|
}
|
||||||
|
|
||||||
int i = 0;
|
if (host->h_aliases)
|
||||||
while (auto * ptr_record = host->h_aliases[i])
|
|
||||||
{
|
{
|
||||||
ptr_records->insert(ptr_record);
|
int i = 0;
|
||||||
i++;
|
while (auto * ptr_record = host->h_aliases[i])
|
||||||
|
{
|
||||||
|
ptr_records->insert(ptr_record);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user