From e155a3bf1fcc6cd58a407da20845eaae88aa3991 Mon Sep 17 00:00:00 2001 From: Lexikos Date: Fri, 22 Mar 2024 15:57:16 +1000 Subject: [PATCH] Fixed SysGetIPAddresses causing a Critical Error when IP is unavailable. --- source/script_autoit.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/source/script_autoit.cpp b/source/script_autoit.cpp index 762b7253a..06fa4e895 100644 --- a/source/script_autoit.cpp +++ b/source/script_autoit.cpp @@ -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;