Skip to content

Commit

Permalink
Reinforced the implementation of the FQDN resolver
Browse files Browse the repository at this point in the history
The previous version was prone to crashes when DNS was not returning
a well-formed result.
  • Loading branch information
iagaponenko committed Jan 30, 2025
1 parent 4776612 commit 3d14871
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/util/common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ string get_current_host_fqdn(bool all) {
hints.ai_family = AF_UNSPEC; /* either IPV4 or IPV6 */
hints.ai_socktype = SOCK_STREAM; /* IP */
hints.ai_flags = AI_CANONNAME; /* canonical name */
hints.ai_canonname = NULL;
struct addrinfo* info;
while (true) {
int const retCode = getaddrinfo(hostname.data(), "http", &hints, &info);
Expand All @@ -63,6 +64,10 @@ string get_current_host_fqdn(bool all) {
}
string fqdn;
for (struct addrinfo* p = info; p != NULL; p = p->ai_next) {
if (p->ai_canonname == NULL) {
throw runtime_error("Registry::" + string(__func__) +
" getaddrinfo failed: ai_canonname is NULL");
}
if (!fqdn.empty()) {
if (!all) break;
fqdn += ",";
Expand Down

0 comments on commit 3d14871

Please sign in to comment.