]> git.ipfire.org Git - thirdparty/mtr.git/commitdiff
options: reject invalid bit patterns 625/head
authoryvs <VSYakovetsky@gmail.com>
Fri, 8 May 2026 13:20:38 +0000 (17:20 +0400)
committerDarafei Praliaskouski <me@komzpa.net>
Fri, 8 May 2026 13:20:38 +0000 (17:20 +0400)
Port the bitpattern validation from yvs2014/mtr085. Only -1 selects a random payload pattern; other negative values and values above 255 are rejected instead of silently enabling random mode.

Ported-from: yvs2014/mtr085@e100fd72be37f0a98d6893db7e0baa8a5b81b72a

Original-author: yvs <VSYakovetsky@gmail.com>

man/mtr.8.in
ui/mtr.c

index 35bc545e5ae360d429dec5149b0946131ed7a39f..f0f4d15245adb84e9a55b0db7591d20db70e0882 100644 (file)
@@ -400,9 +400,8 @@ If set to a negative number, every iteration will use a different, random
 packet size up to that number.
 .TP
 .B \-B \fINUM\fR, \fB\-\-bitpattern \fINUM
-Specifies bit pattern to use in payload.  Should be within range 0 - 255.  If
-.I NUM
-is greater than 255, a random pattern is used.
+Specifies bit pattern to use in payload.  Should be within range 0 - 255,
+or -1 to use a random pattern.
 .TP
 .B \-G \fISECONDS\fR, \fB\-\-gracetime \fISECONDS
 Use this option to specify the positive number of seconds to wait for responses
index 32fbc751ad260423ea25991c9fb24fdc62950091..a8e4021776a6381f5248e0d7388971586d3f9b0d 100644 (file)
--- a/ui/mtr.c
+++ b/ui/mtr.c
@@ -409,7 +409,7 @@ static void parse_arg(
         {"interval", 1, NULL, 'i'},
         {"report-cycles", 1, NULL, 'c'},
         {"psize", 1, NULL, 's'},        /* overload psize<0, ->rand(min,max) */
-        {"bitpattern", 1, NULL, 'B'},   /* overload B>255, ->rand(0,255) */
+        {"bitpattern", 1, NULL, 'B'},   /* -1 random, otherwise 0..255 */
         {"tos", 1, NULL, 'Q'},  /* typeof service (0,255) */
         {"mpls", 0, NULL, 'e'},
         {"interface", 1, NULL, 'I'},
@@ -599,8 +599,10 @@ static void parse_arg(
         case 'B':
             ctl->bitpattern =
                 strtoint_or_err(optarg, "invalid argument");
-            if (ctl->bitpattern > 255)
-                ctl->bitpattern = -1;
+            if (ctl->bitpattern < -1 || ctl->bitpattern > 255) {
+                error(EXIT_FAILURE, 0, "value out of range (-1 - 255): %s",
+                      optarg);
+            }
             break;
         case 'G':
             ctl->GraceTime = strtofloat_or_err(optarg, "invalid argument");