On Thu, Sep 23, 2010 at 08:06:42AM -0400, Laine Stump wrote:
>
>> + sprintf(ipBuf,"%d",inet_ntoa(ipAddr));
> Where is the guarantee that ipBuf is big enough for this sprintf, or is
> there a possibility of buffer overflow?
Beyond that, I'm confused about what this sprintf thinks it's printing -
it looks to me like it's printing out the decimal conversion of the
*address* of a char* that contains an ASCII representation of an IP
address. ???
BTW, note that inet_ntoa is not threadsafe (the same static buffer is
reused by all callers in all threads of the process), so it shouldn't be
used. Better to use inet_ntop instead.
>> + "%d.%d.%d.%d", (ip>> 0)& 255, (ip>>
8)& 255,
>> + (ip>> 16)& 255, (ip>> 24)& 255);
> Maybe it's just me, but I prefer 0xff rather than 255 when masking bits.
> If we could guarantee that gnulib gives us %hhd support, you could
> avoid the mask (and just do the shift).
Why not use inet_ntop() instead?
None of the inet_XXXX() APIs should ever be used in modern code.
The getaddrinfo + getnameinfo functions suffice for all use cases
previously handled by inet_XXXX()
Regards,
Daniel
--
|: Red Hat, Engineering, London -o-
http://people.redhat.com/berrange/ :|
|:
http://libvirt.org -o-
http://virt-manager.org -o-
http://deltacloud.org :|
|:
http://autobuild.org -o-
http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|