Courtnix Blog

Fix MTR Report in Ubuntu 24.04



TL;DR

Run this:

#!/usr/bin/env sh

sed -i 's/Types: deb/Types: deb deb-src/g' /etc/apt/sources.list.d/ubuntu.sources
cd /tmp
apt-get update
apt-get install -y dpkg-dev
apt-get source mtr
apt-get build-dep mtr
cd mtr-0.95

# Get patch
curl -o debian/patches/5908af4c19188cb17b62f23368b6ef462831a0cb.patch https://github.com/traviscross/mtr/commit/5908af4c19188cb17b62f23368b6ef462831a0cb.patch

# Apply patch
patch -p1 < debian/patches/5908af4c19188cb17b62f23368b6ef462831a0cb.patch

# Build package
dpkg-buildpackage -rfakeroot -uc -b

# Install package
find /tmp -name "*mtr-tiny*.deb" -exec dpkg -i {} \;

The Fix

I’ve been meaning to upgrade some computers to Ubuntu 24.04 LTS, but have run into a problem with the MTR package. I frequently use the -r flag to generate reports. However, there is a known issue with the report feature in Ubuntu 24.04 due to Ubuntu enabling "string_fortified" by default. The good news is the fix is pretty simple, as seen in the patch below:

From 5908af4c19188cb17b62f23368b6ef462831a0cb Mon Sep 17 00:00:00 2001
From: Marcus Meissner <meissner@suse.de>
Date: Tue, 11 Apr 2023 16:05:36 +0200
Subject: [PATCH] fixed the sizes passed into snprintf

---
 ui/report.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/ui/report.c b/ui/report.c
index 93014808..61f2c74b 100644
--- a/ui/report.c
+++ b/ui/report.c
@@ -140,7 +140,7 @@ void report_close(
             continue;

         snprintf(fmt, sizeof(fmt), "%%%ds", data_fields[j].length);
-        snprintf(buf + len, sizeof(buf), fmt, data_fields[j].title);
+        snprintf(buf + len, sizeof(buf) - len, fmt, data_fields[j].title);
         len += data_fields[j].length;
     }
     printf("%s\n", buf);
@@ -172,10 +172,10 @@ void report_close(

             /* 1000.0 is a temporary hack for stats usec to ms, impacted net_loss. */
             if (strchr(data_fields[j].format, 'f')) {
-                snprintf(buf + len, sizeof(buf), data_fields[j].format,
+                snprintf(buf + len, sizeof(buf) - len, data_fields[j].format,
                          data_fields[j].net_xxx(at) / 1000.0);
             } else {
-                snprintf(buf + len, sizeof(buf), data_fields[j].format,
+                snprintf(buf + len, sizeof(buf) - len, data_fields[j].format,
                          data_fields[j].net_xxx(at));
             }
             len += data_fields[j].length;

And the patch was committed here. Since the patch was back in April 11, 2023, I was hoping that after a bug report being filed on 2024-07-04 on launchpad that it would hopefully make its way to 24.04.1. Sadly, it didn’t. So, for anyone who wants to patch this for themselves, here is how.

Process

First, you want to update /etc/apt/sources.list.d/ubuntu.sources and include deb-src in the "Types" lines to look like so:

Types: deb deb-src

Next, we need to install dpkg-dev

cd /tmp; apt-get update; apt-get install -y dpkg-dev

Next, you can get the source for mtr and get the build dependencies for it

apt-get source mtr; apt-get build-dep mtr

Next, I fetched the patch and put it in the debian/patches dir, you can put it anywhere you like

cd mtr-0.95; curl -o debian/patches/5908af4c19188cb17b62f23368b6ef462831a0cb.patch https://github.com/traviscross/mtr/commit/5908af4c19188cb17b62f23368b6ef462831a0cb.patch

When you get the source, the patches get applied too, so you need to apply the patch yourself

patch -p1 < debian/patches/5908af4c19188cb17b62f23368b6ef462831a0cb.patch

With the patch applied, build the package with this command:

dpkg-buildpackage -rfakeroot -uc -b

Finally, install the package;

dpkg -i ./mtr-tiny_0.95-1.1build2_amd64.deb

I install the mtr-tiny package because I don’t need the x11 version, but it is also there.