https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=289198

            Bug ID: 289198
           Summary: inet_net_pton is broken with AF_INET6
           Product: Base System
           Version: 14.3-RELEASE
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Only Me
          Priority: ---
         Component: misc
          Assignee: [email protected]
          Reporter: [email protected]
 Attachment #263348 text/plain
         mime type:

Created attachment 263348
  --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=263348&action=edit
test code

I believe inet_net_pton(3) with the first argument set to AF_INET6
is utterly broken:

The manual page claims:

        The inet_net_pton() function converts a presentation format Internet
        network number ... to network format (usually a struct in_addr...).
        It returns the number of bits (...specified with /CIDR).

        The currently supported values for af are AF_INET and AF_INET6.

See the test code in the attachment.

The code first uses inet_net_pton to parse a string representation
of an address in argv[1] and then converts it back to a string using
inet_ntop(3):

        $ make bug
        cc -O2 -pipe  bug.c  -o bug
        $
        $ ./bug fe80::1/64
         input : fe80::1/64
        network : fe80:0:0:1::
        $
        $ ./bug fe80::f000:74ff:fe54:bed2/64
         input : fe80::f000:74ff:fe54:bed2/64
        network : bed2::
        $
        $
        $ ./bug fe80::f000:74ff:fe54:bed2
         input : fe80::f000:74ff:fe54:bed2
        network : fe80::f000:74ff:fe54:bed2
        $
        $
        $ ./bug ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/64
        bug: bad address: No such file or directory
        $
        $ ./bug ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff
         input : ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff
        network : ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff

Staring at the current implementation for a bit reveals that it is
in fact a copy of inet_pton with a few changes. Except that it
doesn't work.

Looking at the OpenBSD version of the same function it feels like
that would be easy to import it. It is exactly implemented how one
would expect it to be.

See
https://cvsweb.openbsd.org/src/lib/libc/net/inet_net_pton.c?rev=1.14&content-type=text/x-cvsweb-markup
at the very bottom.

I tested this on 14.3-RELEASE-p2 amd64. The code hasn't been touched
in main so I believe it's broken there too.

Nico

-- 
You are receiving this mail because:
You are the assignee for the bug.

Reply via email to