Skip to content

Instantly share code, notes, and snippets.

@icedream
Last active October 9, 2024 14:43
Show Gist options
  • Save icedream/f34af692ae6a2d63986f149a9001ca54 to your computer and use it in GitHub Desktop.
Save icedream/f34af692ae6a2d63986f149a9001ca54 to your computer and use it in GitHub Desktop.
Patched mtr for Ubuntu 24

Report mode patches for MTR on Ubuntu 24

Quick and dirty Dockerfile that will build a patched binary and source package for MTR on Ubuntu 24. They still ship a broken version on Ubuntu which does not include the necessary fixes.

You only need Docker and this command:

docker build --rm --output type=local,dest=output/ https://gist.github.com/icedream/f34af692ae6a2d63986f149a9001ca54/raw/Dockerfile

This will automatically fetch the Dockerfile, run it, and output the files to a output/ subdirectory. You can install the packages from there with apt install -y <path-to-deb> or dpkg -i <path-to-deb>.

You can also run the embedded comparison test. First mtr call should fail and log, second mtr call should succeed:

docker build --rm --progress plain --target test https://gist.github.com/icedream/f34af692ae6a2d63986f149a9001ca54/raw/Dockerfile

Test should look something like this:

#20 [test 4/7] RUN if mtr -r -m 2  -G 1 -Z 1 -i 1 -c 1 localhost; then echo "does not crash anymore" && exit 1; else echo "yep, crashes, let's replace it"; fi
#20 2.038 *** buffer overflow detected ***: terminated
#20 2.134 Aborted (core dumped)
#20 2.134 yep, crashes, let's replace it
#20 DONE 2.2s

#21 [test 5/7] COPY --from=0 /usr/src/*+icedream.* /var/tmp
#21 DONE 0.1s

#22 [test 6/7] RUN DEBIAN_FRONTEND=noninteractive apt install -y /var/tmp/mtr-tiny*+icedream.*.deb
[...]

#23 [test 7/7] RUN if ! mtr -r -m 2  -G 1 -Z 1 -i 1 -c 1 localhost; then echo "patched version crashes..." && exit 1; else echo "yep, fixed"; fi
#23 2.010 Start: 2024-10-09T14:40:20+0000
#23 2.010 HOST: buildkitsandbox             Loss%   Snt   Last   Avg  Best  Wrst StDev
#23 2.010   1.|-- localhost                  0.0%     1    0.0   0.0   0.0   0.0   0.0
#23 2.010 yep, fixed
#23 DONE 2.0s

# Dockerfile to build a patched mtr package for Ubuntu 24.
#
# Run this directly with this command, you don't need anything else than
# Docker:
#
# docker build --rm --output type=local,dest=output/ https://gist.github.com/icedream/f34af692ae6a2d63986f149a9001ca54/raw/Dockerfile
#
# This will give you an output/ directory with source and binary packages
# for a version suffixed +icedream.1 containing the patches.
#
# Author: Carl Kittelberger <[email protected]>
FROM ubuntu:24.04
# TODO - deal with sources.list* files, not just *.sources
RUN find /etc/apt -name '*.sources' -exec sed -i 's,Types: deb$,Types: deb deb-src,g' {} \;
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update
RUN apt-get install -y --no-install-recommends dpkg-dev devscripts build-essential
WORKDIR /usr/src/
ARG PKG=mtr
# install dependencies
RUN apt-get build-dep -y $PKG
# download source code and unpack, removing archives
RUN apt-get source $PKG
# apply patches
ARG MODIFIER=icedream
ARG [email protected]
ARG DEBFULLNAME="Carl Kittelberger"
ARG [email protected]
ADD https://github.com/traviscross/mtr/commit/5908af4c19188cb17b62f23368b6ef462831a0cb.patch /var/tmp/0001-Patch-fixed-the-sizes-passed-into-snprintf.patch
RUN cd mtr-*/ && for patch in /var/tmp/*.patch; do patch -p1 -i "$patch" && rm "$patch"; done
RUN cd mtr-*/ && debchange -l "+$MODIFIER." "Fix crash when using report mode" </dev/null
RUN cd mtr-*/ && EDITOR=/bin/true dpkg-source -q --commit . "1000-Fix-crash-when-using-report-mode.patch"
# compile patched package
RUN cd mtr-*/ && dpkg-buildpackage -us -uc -F </dev/null
# clean up source code tree
RUN rm -rf mtr-*/
###
# Just to test the package out
FROM ubuntu:24.04 AS test
RUN apt-get update
ARG MODIFIER=icedream
RUN DEBIAN_FRONTEND=noninteractive apt install -y mtr-tiny
RUN if mtr -r -m 2 -G 1 -Z 1 -i 1 -c 1 localhost; then echo "does not crash anymore" && exit 1; else echo "yep, crashes, let's replace it"; fi
COPY --from=0 /usr/src/*+$MODIFIER.* /var/tmp
RUN DEBIAN_FRONTEND=noninteractive apt install -y /var/tmp/mtr-tiny*+$MODIFIER.*.deb
RUN if ! mtr -r -m 2 -G 1 -Z 1 -i 1 -c 1 localhost; then echo "patched version crashes..." && exit 1; else echo "yep, fixed"; fi
###
# Copy build output to its own files only layer
FROM scratch
ARG MODIFIER=icedream
COPY --from=0 /usr/src/*+$MODIFIER.* /
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment