bug in 3.2.0 nmblookup

Alan DeKok aland at ox.org
Fri Jul 4 06:46:04 GMT 2008

Jeremy Allison wrote:
>> --- /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;
>>  }

  That looks like a pointer aliasing bug to me.

  Newer versions of GCC are more aggressive about optimizations.  They
may notice that the assignment "sa->sin_addr = ip" is just before the
closing brace... and that "sa" is a local variable, which isn't used
after that.  So... the assignment can safely be optimized away.

  Yes... I got hit by this recently.  The solution (horrible as it
sounds) was to memcpy back and forth between "struct sockaddr_storage"
and "struct sockaddr_in*".

  Just a heads up.  If you suddenly see that the IP's are always zero,
this is what's going on.

  Alan DeKok.

More information about the samba-technical mailing list