Skip to content

Commit

Permalink
fruity: Fix crash in the Linux getifaddrs() logic
Browse files Browse the repository at this point in the history
Which failed to handle interfaces without an address.
  • Loading branch information
oleavr committed Feb 20, 2025
1 parent 1ed5590 commit 26d9b9b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
10 changes: 6 additions & 4 deletions src/fruity/device-monitor-linux.vala
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,14 @@ namespace Frida.Fruity {
Linux.Network.IfAddrs ifaddrs;
Linux.Network.getifaddrs (out ifaddrs);
for (unowned Linux.Network.IfAddrs candidate = ifaddrs; candidate != null; candidate = candidate.ifa_next) {
if (candidate.ifa_name != ifname)
unowned Posix.SockAddr? address = candidate.ifa_addr;
if (address == null || address.sa_family != Posix.AF_INET6)
continue;
if (candidate.ifa_addr.sa_family != Posix.AF_INET6)

if (candidate.ifa_name != ifname)
continue;
return (InetSocketAddress)
SocketAddress.from_native ((void *) candidate.ifa_addr, sizeof (Posix.SockAddrIn6));

return (InetSocketAddress) SocketAddress.from_native ((void *) address, sizeof (Posix.SockAddrIn6));
}

throw new Error.NOT_SUPPORTED ("Unable to resolve interface address");
Expand Down
6 changes: 4 additions & 2 deletions src/fruity/device-monitor.vala
Original file line number Diff line number Diff line change
Expand Up @@ -1482,13 +1482,15 @@ namespace Frida.Fruity {
Linux.Network.IfAddrs ifaddrs;
Linux.Network.getifaddrs (out ifaddrs);
for (unowned Linux.Network.IfAddrs candidate = ifaddrs; candidate != null; candidate = candidate.ifa_next) {
if (candidate.ifa_addr.sa_family != Posix.AF_INET6)
unowned Posix.SockAddr? address = candidate.ifa_addr;
if (address == null || address.sa_family != Posix.AF_INET6)
continue;

if (!ncm_interfaces.contains (candidate.ifa_name))
continue;

device_ifaddrs.add ((InetSocketAddress) SocketAddress.from_native ((void *) candidate.ifa_addr, sizeof (Posix.SockAddrIn6)));
device_ifaddrs.add ((InetSocketAddress) SocketAddress.from_native ((void *) address,
sizeof (Posix.SockAddrIn6)));
}
if (device_ifaddrs.is_empty && !ncm_interfaces.is_empty)
throw new Error.NOT_SUPPORTED ("no IPv6 address on NCM network interface");
Expand Down

0 comments on commit 26d9b9b

Please sign in to comment.