Hi,

On Mon, Feb 09, 2015 at 10:04:03AM +0100, Arne Schwabe wrote:
> > --- a/src/openvpn/mroute.c
> > +++ b/src/openvpn/mroute.c
> > @@ -426,8 +426,16 @@ mroute_addr_print_ex (const struct mroute_addr *ma,
> >       break;
> >     case MR_ADDR_IPV6:
> >       {
> > -       buf_printf (&out, "%s",
> > -             print_in6_addr( *(struct in6_addr*)&maddr.addr, 0, gc)); 
> > +       if ( IN6_IS_ADDR_V4MAPPED( (struct in6_addr*)&maddr.addr ) )
> > +         {
> > +           buf_printf (&out, "%s",
> > +                print_in_addr_t( *(in_addr_t*)(&maddr.addr[12]), 
> > IA_NET_ORDER, gc));
> Have you checked that this is endian safe?

Yep, both by running on i386 and on sparc64 - and then by staring at the
code and wondering why it works.

Thing is that print_in_addr_t() takes a flag, IA_NET_ORDER, which tells it
"that 32bit thingie you're printing now is in network byte order", so it
will not call htonl() on it before passing to inet_ntoa(), which wants
network byte order.

(And the IPv6 address is "just an array of 16 octets", no possible confusion
here with 32bit integer representation)

From the Linux man page:

---- snip ----
       The inet_ntoa() function converts the Internet host address  in,  given
       in  network  byte  order,  to a string in IPv4 dotted-decimal notation.
       The string is returned in a statically allocated buffer,  which  subse-
       quent calls will overwrite.
---- snip ----

(interesting enough, the FreeBSD man page only mentions "network byte
order" for inet_ntop()...)


> > +   {
> > +     struct in_addr ia;
> > +     ia.s_addr = *(in_addr_t *)&addr->addr.in6.sin6_addr.s6_addr[12] ;
> > +     openvpn_snprintf (name_buf, sizeof (name_buf), "%s_ip", name_prefix);
> > +     openvpn_snprintf (buf, sizeof(buf), "%s", inet_ntoa(ia) );
> Same as above.

Same as above :-) - I admit that this is all amazingly ugly, but it is
technically correct.  The IPv6 address is always in network byte order,
and inet_ntoa() wants "its" 32bit that way...

In the end, this is the same code as in the first place, except that we
have no gc around here, and print_in_addr_t() wants one...   so I did it
with the existing buf.

> Otherwise ACK from me.

Thanks.  Will proceed to merge this bikeshed :-)

gert

-- 
USENET is *not* the non-clickable part of WWW!
                                                           //www.muc.de/~gert/
Gert Doering - Munich, Germany                             g...@greenie.muc.de
fax: +49-89-35655025                        g...@net.informatik.tu-muenchen.de

Attachment: pgpxb_47kNe0k.pgp
Description: PGP signature

Reply via email to