Skip to content

Commit

Permalink
Fixed SysGetIPAddresses causing a Critical Error when IP is unavailable.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lexikos committed Mar 22, 2024
1 parent 2fd0ecf commit e155a3b
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions source/script_autoit.cpp
Expand Up @@ -113,9 +113,14 @@ bif_impl FResult SysGetIPAddresses(IObject *&aRetVal)
}

char host_name[256];
gethostname(host_name, _countof(host_name));
HOSTENT *lpHost = gethostbyname(host_name);

HOSTENT *lpHost = nullptr;
// gethostname would probably only fail in exceptional circumstances, such as a damaged OS install
// where networking is very broken. Running in safe mode without networking was confirmed to cause
// gethostbyname to return NULL.
if (gethostname(host_name, _countof(host_name)) == 0)
lpHost = gethostbyname(host_name);

if (lpHost)
for (int i = 0; lpHost->h_addr_list[i]; ++i)
{
IN_ADDR inaddr;
Expand Down

0 comments on commit e155a3b

Please sign in to comment.