bug in 3.2.0 nmblookup
Sam Liddicott
sam at liddicott.com
Fri Jul 4 07:33:36 GMT 2008
Alan DeKok wrote:
> 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.
>
Thats sick!
sa may be a local variable but it is a pointer. Since when did gcc think
that local pointers only point locally?
What if a function scope pointer was initialized from an argument struct
(for convenience) would they optimize away that last use of that pointer
too?
function blah(struct suff* arg) {
struct secret *secret=stuff->secret;
// does this get opimized away as secret is going out of scope
secret->word="shh";
}
If I'm not wrong, this must be a gcc bug.
Sam
> 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