bug in 3.2.0 nmblookup

Zachary Loafman zachary.loafman at isilon.com
Fri Jul 4 08:31:34 GMT 2008


> >> --- /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.

In the case above, the aliasing occurs in the same function, the
original pointer ("ss") is passed into the function, and the compiler is
required to act on all of those assignments (because neither of the
pointers can be proven to reference local variables). Furthermore, the
assignments don't reference the same memory, so the actual order of the
assignments is irrelevant (one of the common aliasing optimization
issues is that the compiler should be allowed to reorder the assignments
for distinct pointers, but it's irrelevant here). There's no possible
aliasing bug here.

That said, I still would've coded it as sa->sin_family = AF_INET.
Flip-flopping types is fugly. :)

...Zach


More information about the samba-technical mailing list