bug in 3.2.0 nmblookup

Jeremy Allison jra at samba.org
Fri Jul 4 05:10:48 GMT 2008


On Thu, Jul 03, 2008 at 04:18:29PM -0700, Herb Lewis wrote:
> On freebsd 4.6.2 at least, the getnameinfo function expects the length
> field inside the struct sockaddr to match the salen arg or it returns
> an error. This causes nmblookup to not print the address of the found
> name in a query like the following
>
> nmblookup -R -U 172.17.132.16 nt4pdc#20
>
> The following patch fixes this. I don't have IPV6 so could not actually
> test the AF_INET6 portion of the fix.
>
>
> --- /tmp/tmp.66554.0    Thu Jul  3 16:02:36 2008
> +++ source/lib/util_sock.c Thu Jul  3 16:02:00 2008
> @@ -366,6 +366,7 @@
>         struct sockaddr_in *sa = (struct sockaddr_in *)ss;
>         memset(ss, '\0', sizeof(*ss));
>         ss->ss_family = AF_INET;
> +       ss->ss_len = sizeof(struct sockaddr_in);
>         sa->sin_addr = ip;
>  }
>
> @@ -380,6 +381,7 @@
>         struct sockaddr_in6 *sa = (struct sockaddr_in6 *)ss;
>         memset(ss, '\0', sizeof(*ss));
>         ss->ss_family = AF_INET6;
> +       ss->ss_len = sizeof(struct sockaddr_in6);
>         sa->sin6_addr = ip;
>  }

The problem is that many systems don't have ss_len
inside their sockaddr_storage struct so this fix
as posted will break everything *but* BSD.

The correct place to fix this is in lib/system.c,
inside sys_getnameinfo(). Look at the fix inside
there that was added for Solaris :

        /*
         * For Solaris we must make sure salen is the
         * correct length for the incoming sa_family.
         */

something similar could be added for *BSD. But make
sure it's not an #ifdef BSD, but a configure check
for ss_len first. And be careful, I remember AIX
has a nasty definition of ss_len that messes things
up. This is a can of worms you're opening here :-).

Jeremy.


More information about the samba-technical mailing list