Skip to content

Commit

Permalink
Exit gracefully if conf.intf does not exist
Browse files Browse the repository at this point in the history
If the interface named in 'conf.intf' does not exist then there is a
segfault. The user is not notified of the problem.
So, print an error message informing the user and exit gracefully instead
of a segfault.

This has been reported in Ubuntu.

Signed-off-by: Sudip Mukherjee <[email protected]>
  • Loading branch information
sudipm-mukherjee committed Dec 31, 2023
1 parent a6691ae commit dcc4a4e
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <err.h>
#include <sys/socket.h>
#include <net/if.h>
#include <ifaddrs.h>

#include <uwifi/packet_sock.h>
#include <uwifi/util.h>
Expand Down Expand Up @@ -570,6 +571,25 @@ static void generate_mon_ifname(char *const buf, const size_t buf_size)
}
}

static bool check_if_exists(const char *const interface)
{
struct ifaddrs *ifaddr, *ifa;
bool found = false;

if (getifaddrs(&ifaddr) == -1) {
printf("can not check interface names, continuing\n");
return true;
}
for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
if (strcmp(ifa->ifa_name, interface) == 0) {
found = true;
break;
}
}
freeifaddrs(ifaddr);
return found;
}

int main(int argc, char** argv)
{
sigset_t workmask;
Expand Down Expand Up @@ -612,6 +632,10 @@ int main(int argc, char** argv)
conf.intf.sock = net_open_client_socket(conf.serveraddr, conf.port);
cc_list_head_init(&conf.intf.wlan_nodes);
} else {
if (!check_if_exists(conf.intf.ifname)) {
fprintf(stderr, "invalid interface name, please check configuration\n");
return(-EINVAL);
}
ifctrl_init();
ifctrl_iwget_interface_info(&conf.intf);

Expand Down

0 comments on commit dcc4a4e

Please sign in to comment.