From a896bc9193cfbc48a48e242d2470777897228b29 Mon Sep 17 00:00:00 2001 From: Darafei Praliaskouski Date: Thu, 7 May 2026 23:45:42 +0400 Subject: [PATCH] fix: reject unspecified destination addresses Suggested-by: yvs2014 <30629719+yvs2014@users.noreply.github.com> --- ui/gtk.c | 7 +++++-- ui/net.c | 13 +++++++++---- ui/net.h | 2 +- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/ui/gtk.c b/ui/gtk.c index 742c5c9..2d865d2 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -248,8 +248,8 @@ static gint Host_activate( ctl->af = DEFAULT_AF; // should this obey the cmd line option? ctl->Hostname = gtk_entry_get_text(GTK_ENTRY(entry)); - if (get_addrinfo_from_name(ctl, &res, ctl->Hostname) == 0) { - net_reopen(ctl, res); + if (get_addrinfo_from_name(ctl, &res, ctl->Hostname) == 0 && + net_reopen(ctl, res) == 0) { freeaddrinfo(res); net_send_batch(ctl); /* If we are "Paused" at this point it is usually because someone @@ -257,6 +257,9 @@ static gint Host_activate( gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(Pause_Button), 0); } else { int pos = strlen(gtk_entry_get_text(GTK_ENTRY(entry))); + if (res) { + freeaddrinfo(res); + } gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(Pause_Button), 1); gtk_editable_insert_text(GTK_EDITABLE(entry), ": not found", -1, &pos); diff --git a/ui/net.c b/ui/net.c index ed71a56..3aa7728 100644 --- a/ui/net.c +++ b/ui/net.c @@ -768,24 +768,28 @@ int net_open( { int err; + if (!addrcmp(sockaddr_addr_offset(res->ai_addr), &ctl->unspec_addr, res->ai_family)) + return -1; + /* Spawn the mtr-packet child process */ err = open_command_pipe(ctl, &packet_command_pipe); if (err) { return err; } - net_reopen(ctl, res); - - return 0; + return net_reopen(ctl, res); } -void net_reopen( +int net_reopen( struct mtr_ctl *ctl, struct addrinfo *res) { int at; + if (!addrcmp(sockaddr_addr_offset(res->ai_addr), &ctl->unspec_addr, res->ai_family)) + return -1; + for (at = 0; at < MaxHost; at++) { memset(&host[at], 0, sizeof(host[at])); } @@ -809,6 +813,7 @@ void net_reopen( net_find_local_address(ctl); } + return 0; } diff --git a/ui/net.h b/ui/net.h index 354c998..2488d13 100644 --- a/ui/net.h +++ b/ui/net.h @@ -34,7 +34,7 @@ extern int net_open( struct mtr_ctl *ctl, struct addrinfo *res); -extern void net_reopen( +extern int net_reopen( struct mtr_ctl *ctl, struct addrinfo *res); extern void net_reset( -- 2.47.3