[Bug 258048] 'ping' option parsing broken after merging in 'ping6' code.

From: <bugzilla-noreply_at_freebsd.org>
Date: Wed, 25 Aug 2021 20:46:59 +0000
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=258048

            Bug ID: 258048
           Summary: 'ping' option parsing broken after merging in 'ping6'
                    code.
           Product: Base System
           Version: CURRENT
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Only Me
          Priority: ---
         Component: bin
          Assignee: bugs_at_FreeBSD.org
          Reporter: ghuckriede_at_blackberry.com

Created attachment 227435
  --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=227435&action=edit
Potential Fix

Overview:
When ping6 was merged into ping, the option parsing was broken.

During the first pass of the options, to determine ipv4 or ipv6, only options
"46" are provided to getopt().  This causes getopt() to match any '4' or '6',
because it believes these are the only valid options.

Below are some examples of how the first pass into getopt() is interpreted:
"-c6" will match 'c' as invalid (which is ignored) and '6' as ipv6 (instead of
a count of 6)
"-s46" will match 's' as invalid (which is ignored), '4' as ipv4, and '6' as
ipv6 (instead of a size of 46).

I've provided a diff that moves the option string creation to main.h and uses
that for all getopt() calls.

The diff also includes the following additional fixes:
- Reorder the PING6ADDOPTS options alphabetically like the PING4ADDOPTS.
- Add missing space after the "[-m ttl]" option the in usage() text.
- Swap the "aA" with "Aa" in the ping 6 usage() text to match PING6ADDOPTS.
- Add some #ifdef IPSEC around some unused declarations.


Steps to Reproduce:
ping -s46 127.0.0.1
ping -s46 ::1
ping -4 -c6 127.0.0.1
ping -6 -c4 ::1       
ping -4 -t6 127.0.0.1
ping -6 -t4 ::1       
ping -6 -t4 ::1
ping -6 -z4 -c1 ::1
ping -s6 -c1 127.0.0.1
ping -s4 -c1 ::1

Actual Results:
All the "valid" command above return the following errors.
"ping: -4 and -6 cannot be used simultaneously"
OR
"ping: IPv6 requested but IPv4 target address provided"

Expected Results:
ping should not interpret '4' and '6' in the values of other options as
"options".

Build Date & Hardware: 
git HEAD _at_ 9f7a81b133c715f649136dcd0ad004e4180c56c9

Additional Information:
none

-- 
You are receiving this mail because:
You are the assignee for the bug.
Received on Wed Aug 25 2021 - 20:46:59 UTC

Original text of this message