From 0b015daff73a58ad8ee8fca27938fa9e7d09e32b Mon Sep 17 00:00:00 2001 From: squidbus <175574877+squidbus@users.noreply.github.com> Date: Fri, 1 Nov 2024 05:29:24 -0700 Subject: [PATCH] netctl: Add null check for gethostbyname output. (#1468) --- src/core/libraries/network/netctl.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/core/libraries/network/netctl.cpp b/src/core/libraries/network/netctl.cpp index e7a69611..d3f83c29 100644 --- a/src/core/libraries/network/netctl.cpp +++ b/src/core/libraries/network/netctl.cpp @@ -170,14 +170,15 @@ int PS4_SYSV_ABI sceNetCtlGetInfo(int code, OrbisNetCtlInfo* info) { "127.0.0.1"); // placeholder in case gethostbyname can't find another ip char devname[80]; gethostname(devname, 80); - struct hostent* resolved = gethostbyname(devname); - for (int i = 0; resolved->h_addr_list[i] != nullptr; ++i) { - struct in_addr addrIn; - memcpy(&addrIn, resolved->h_addr_list[i], sizeof(u32)); - char* addr = inet_ntoa(addrIn); - if (strcmp(addr, "127.0.0.1") != 0) { - strcpy(info->ip_address, addr); - break; + if (struct hostent* resolved = gethostbyname(devname)) { + for (int i = 0; resolved->h_addr_list[i] != nullptr; ++i) { + struct in_addr addrIn; + memcpy(&addrIn, resolved->h_addr_list[i], sizeof(u32)); + char* addr = inet_ntoa(addrIn); + if (strcmp(addr, "127.0.0.1") != 0) { + strcpy(info->ip_address, addr); + break; + } } } break;