netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Luca Boccassi <bluca@debian.org>
To: netdev@vger.kernel.org
Subject: [PATCH iproute2] iproute: fix printing resolved localhost
Date: Sun, 28 Feb 2021 12:45:20 +0000	[thread overview]
Message-ID: <20210228124520.30005-1-bluca@debian.org> (raw)

format_host_rta_r might return a cached hostname
via its return value and not use the input buffer.

Before:

$ ip -resolve -6 route
 dev lo proto kernel metric 256 pref medium

After:

$ ip/ip -resolve -6 route
localhost dev lo proto kernel metric 256 pref medium

Bug-Debian: https://bugs.debian.org/983591

Reported-by: Axel Scheepers <axel.scheepers76@gmail.com>
Signed-off-by: Luca Boccassi <bluca@debian.org>
---
 ip/iproute.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/ip/iproute.c b/ip/iproute.c
index 291f1a58..5853f026 100644
--- a/ip/iproute.c
+++ b/ip/iproute.c
@@ -796,9 +796,10 @@ int print_route(struct nlmsghdr *n, void *arg)
 				 "%s/%u", rt_addr_n2a_rta(family, tb[RTA_DST]),
 				 r->rtm_dst_len);
 		} else {
-			format_host_rta_r(family, tb[RTA_DST],
+			const char *hostname = format_host_rta_r(family, tb[RTA_DST],
 					  b1, sizeof(b1));
-
+			if (hostname)
+				strncpy(b1, hostname, sizeof(b1) - 1);
 		}
 	} else if (r->rtm_dst_len) {
 		snprintf(b1, sizeof(b1), "0/%d ", r->rtm_dst_len);
@@ -818,8 +819,10 @@ int print_route(struct nlmsghdr *n, void *arg)
 				 rt_addr_n2a_rta(family, tb[RTA_SRC]),
 				 r->rtm_src_len);
 		} else {
-			format_host_rta_r(family, tb[RTA_SRC],
+			const char *hostname = format_host_rta_r(family, tb[RTA_SRC],
 					  b1, sizeof(b1));
+			if (hostname)
+				strncpy(b1, hostname, sizeof(b1) - 1);
 		}
 		print_color_string(PRINT_ANY, color,
 				   "from", "from %s ", b1);
-- 
2.30.1


                 reply	other threads:[~2021-02-28 12:46 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210228124520.30005-1-bluca@debian.org \
    --to=bluca@debian.org \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).