Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Mon, 21 Oct 2013 21:59:16 +0200
From: Paul Schutte <sjpschutte@...il.com>
To: musl@...ts.openwall.com
Subject: Re: Re: inet_pton

Hi,

I have tested the suggested fix and this is the result:

:    1 <--
::    1
:::    0
192.168.1.1    0
:192.168.1.1    1 <--
::192.168.1.1    1
:ffff:192.168.1.1    1 <--
::ffff:192.168.1.1    1
.192.168.1.1    0
:.192.168.1.1    0
ffff:c0a8:5e4    0
:ffff:c0a8:5e4    1 <--
0:0:0:0:0:ffff:c0a8:5e4    1
0:0:0:0:ffff:c0a8:5e4    0
0::ffff:c0a8:5e4    1
::0::ffff:c0a8:5e4    0
c0a8    0



Those marked with the <-- are still incorrect.

Regards
Paul


On Mon, Oct 21, 2013 at 4:08 AM, Rich Felker <dalias@...ifal.cx> wrote:

> It's not an annoyance at all, and your test cases may be useful for
> writing a regression test, so I'm replying on-list. As you may have
> noticed, I already fixed the first issue you reported, but the second
> issue does remain. nsz has proposed a simple fix: at line 61,
>
> -                       if (s[j]!='.') return 0;
> +                       if (s[j]!='.' || brk<0) return 0;
>
> I have not checked this yet but I suspect it's correct. Please let me
> know if it works for you.
>
> Rich
>
>
> On Sun, Oct 20, 2013 at 09:35:32PM +0200, Paul Schutte wrote:
> > Hi Rich,
> >
> > I send this directly to you as I think I am starting to annoy the people
> on
> > the list with this.
> >
> > I have done some testing on this and here is the result:
> >
> >
> >
> > proper
> > before  : 0
> > 1  :: 1
> > 1  ::: 0
> > 0  192.168.1.1 0
> > 1  :192.168.1.1 0
> > 1  ::192.168.1.1 1
> > 1  :ffff:192.168.1.1 0
> > 1  ::ffff:192.168.1.1 1
> > 1  .192.168.1.1 0
> > 0  :.192.168.1.1 0
> > 0  ffff:c0a8:5e4 0
> > 0  :ffff:c0a8:5e4 0
> > 1  0:0:0:0:0:ffff:c0a8:5e4 1
> > 1  0:0:0:0:ffff:c0a8:5e4 0
> > 0  0::ffff:c0a8:5e4 1
> > 1  ::0::ffff:c0a8:5e4 0
> > 0  c0a8 0
> > 0
> > The following seems to produce the correct output:
> >
> > --- a/musl/src/network/inet_pton.c
> > +++ b/musl/src/network/inet_pton.c
> > @@ -14,11 +14,11 @@
> >         return -1;
> >  }
> >
> > -int inet_pton(int af, const char *restrict s, void *restrict a0)
> > +int inet_pton(int af, const char *restrict s0, void *restrict a0)
> >  {
> >         uint16_t ip[8];
> >         unsigned char *a = a0;
> > -       const char *z;
> > +       const char *z, *s = s0;
> >         unsigned long x;
> >         int i, j, v, d, brk=-1, need_v4=0;
> >
> > @@ -36,7 +36,13 @@
> >                 return -1;
> >         }
> >
> > -       if (s[0]==':' && s[1]==':') s++;
> > +       if (s[0]==':') {
> > +               if (s[1]==':') {
> > +                       s++;
> > +               } else {
> > +                       return 0;
> > +               }
> > +       }
> >
> >         for (i=0; ; i++, s+=j+1) {
> >                 if (s[0]==':' && brk<0) {
> > @@ -73,6 +79,9 @@
> >                 *a++ = ip[j]>>8;
> >                 *a++ = ip[j];
> >         }
> > +
> > +       if (s==s0) return 0;
> > +
> >         if (need_v4 && inet_pton(AF_INET, (void *)s, a-4) <= 0) return 0;
> >         return 1;
> > }
> >
> >
> > I used the following to test:
> >
> > #include <ctype.h>
> > #include <netdb.h>
> > #include <stdarg.h>
> > #include <stdio.h>
> > #include <stdlib.h>
> > #include <string.h>
> > #include <sys/socket.h>
> > #include <sys/un.h>
> > #include <netinet/in.h>
> > #include <arpa/inet.h>
> >
> > void test(char *s) {
> >         char buf[256];
> >         int musl;
> >         musl=inet_pton(AF_INET6, s, (void*)buf);
> >         printf("%s=%d\n",s,musl);
> > }
> >
> > int main() {
> >
> >         test(":");
> >         test("::");
> >         test(":::");
> >         test("192.168.1.1");
> >         test(":192.168.1.1");
> >         test("::192.168.1.1");
> >         test(":ffff:192.168.1.1");
> >         test("::ffff:192.168.1.1");
> >         test(".192.168.1.1");
> >         test(":.192.168.1.1");
> >         test("ffff:c0a8:5e4");
> >         test(":ffff:c0a8:5e4");
> >         test("0:0:0:0:0:ffff:c0a8:5e4");
> >         test("0:0:0:0:ffff:c0a8:5e4");
> >         test("0::ffff:c0a8:5e4");
> >         test("::0::ffff:c0a8:5e4");
> >         test("c0a8");
> >
> >         return 0;
> > }
> >
> > The output is as follows which seems to be the desired outcome:
> > :=0
> > ::=1
> > :::=0
> > 192.168.1.1=0
> > :192.168.1.1=0
> > ::192.168.1.1=1
> > :ffff:192.168.1.1=0
> > ::ffff:192.168.1.1=1
> > ..192.168.1.1=0
> > :.192.168.1.1=0
> > ffff:c0a8:5e4=0
> > :ffff:c0a8:5e4=0
> > 0:0:0:0:0:ffff:c0a8:5e4=1
> > 0:0:0:0:ffff:c0a8:5e4=0
> > 0::ffff:c0a8:5e4=1
> > ::0::ffff:c0a8:5e4=0
> > c0a8=0
> >
> >
> > Hope I you find this use full.
> >
> > Regards
> > Paul
>

Content of type "text/html" skipped

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.