From: Nikolai Abdusamatov <nick.luft.work@gmail.com> On macOS, pseudo/tunnel interfaces may be returned before hardware interfaces and can have empty or all-zero physical addresses. Applications that rely on GetAdaptersInfo and first-adapter heuristics may propagate an empty MAC and fail authentication. When at least one adapter has a valid physical address, filter out entries with invalid MAC in GetAdaptersInfo enumeration so first returned entries are usable. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=59614 --- dlls/iphlpapi/iphlpapi_main.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/dlls/iphlpapi/iphlpapi_main.c b/dlls/iphlpapi/iphlpapi_main.c index fe2de41c4a3..b9a50bad885 100644 --- a/dlls/iphlpapi/iphlpapi_main.c +++ b/dlls/iphlpapi/iphlpapi_main.c @@ -585,6 +585,21 @@ static void ip_addr_string_init( IP_ADDR_STRING *s, const IN_ADDR *addr, const I s->Context = ctxt; } +static BOOL mac_address_is_zero( const BYTE *addr, ULONG len ) +{ + ULONG i; + + for (i = 0; i < len; i++) if (addr[i]) return FALSE; + return TRUE; +} + +static BOOL adapter_has_valid_mac( const struct nsi_ndis_ifinfo_rw *rw, ULONG max_len ) +{ + return rw->phys_addr.Length > 0 && + rw->phys_addr.Length <= max_len && + !mac_address_is_zero( rw->phys_addr.Address, rw->phys_addr.Length ); +} + /****************************************************************** * GetAdaptersInfo (IPHLPAPI.@) * @@ -596,7 +611,7 @@ static void ip_addr_string_init( IP_ADDR_STRING *s, const IN_ADDR *addr, const I */ DWORD WINAPI GetAdaptersInfo( IP_ADAPTER_INFO *info, ULONG *size ) { - DWORD err, if_count, if_num = 0, uni_count, fwd_count, needed, wins_server_count; + DWORD err, if_count, if_num = 0, if_num_valid = 0, uni_count, fwd_count, needed, wins_server_count; DWORD len, i, uni, fwd; NET_LUID *if_keys = NULL; struct nsi_ndis_ifinfo_rw *if_rw = NULL; @@ -620,8 +635,12 @@ DWORD WINAPI GetAdaptersInfo( IP_ADAPTER_INFO *info, ULONG *size ) { if (if_stat[i].type == IF_TYPE_SOFTWARE_LOOPBACK) continue; if_num++; + if (adapter_has_valid_mac( &if_rw[i], sizeof(info->Address) )) + if_num_valid++; } + if (if_num_valid) if_num = if_num_valid; + if (!if_num) { err = ERROR_NO_DATA; @@ -655,6 +674,8 @@ DWORD WINAPI GetAdaptersInfo( IP_ADAPTER_INFO *info, ULONG *size ) for (i = 0; i < if_count; i++) { if (if_stat[i].type == IF_TYPE_SOFTWARE_LOOPBACK) continue; + if (if_num_valid && !adapter_has_valid_mac( &if_rw[i], sizeof(info->Address) )) + continue; info->Next = info + 1; info->ComboIndex = 0; -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10553