Skip to content

Commit

Permalink
Merge pull request #90 from pablojrl123/getifaddrs-nullptr-fix
Browse files Browse the repository at this point in the history
Prevent null pointer deference in get_mac_address
  • Loading branch information
ABeltramo authored Jul 31, 2024
2 parents bb8559c + a17a260 commit e10d00b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/moonlight-server/platforms/hw_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ std::string get_mac_address(std::string_view local_ip) {
if (!interface.empty()) {
logs::log(logs::trace, "Found interface: {}, looking for MAC address", interface);
for (auto ifa = ifAddrStruct.get(); ifa != NULL; ifa = ifa->ifa_next) {
if (ifa->ifa_name && interface == ifa->ifa_name && ifa->ifa_addr->sa_family == AF_PACKET) {
if (ifa->ifa_name && interface == ifa->ifa_name && ifa->ifa_addr && ifa->ifa_addr->sa_family == AF_PACKET) {
struct sockaddr_ll *s = (struct sockaddr_ll *)(ifa->ifa_addr);
std::vector<std::string> mac(s->sll_halen);
for (int i = 0; i < s->sll_halen; i++) {
Expand All @@ -230,4 +230,4 @@ std::string get_mac_address(std::string_view local_ip) {
local_ip);

return "00:00:00:00:00:00";
}
}

0 comments on commit e10d00b

Please sign in to comment.