[libvirt] Re: [PATCH] syntax-check: prohibit all new uses of gethostby* functions

Daniel P. Berrange berrange at redhat.com
Thu Dec 11 14:36:17 UTC 2008


On Thu, Dec 11, 2008 at 09:28:12AM -0500, R P Herrold wrote:
> On Thu, 11 Dec 2008, Jim Meyering wrote:
> 
> >Good point.
> >Yet another reason not to use gethostbyname.
> >I think it's time to make the prohibition official.
> 
> I sure hope the Cygwin 1.7, which just released yesterday to 
> formal beta trial, and brings in getaddrinfo() for my win 2000 
> porting box, _works_ -- perhaps deprecate it for a while first 
> (understanding it is stated as 'prohibit all new uses ...')?

We use GNULIB which provides compatability for broken/incomplete
OS like cygwin

> >+# Not only do they fail to deal well with ipv6, but the gethostby*
> >+# functions are also not thread-safe.
> 
> I think you mean to say here that the implementation you are 
> encountering is not thread safe

POSIX leaves thread safety undefined, which is just as bad as marking
it explicitly unsafe.

  "The functions gethostbyname() and gethostbyaddr() may  return  pointers
   to  static  data, which may be overwritten by later calls. "

No code can use this function and expect to be safe when using threads.
Even on an OS where its currently safe, there's no guarentee it'll stay
safe in the future

Furthermore they're explicitly deprecated

   "POSIX.1-2001 marks  gethostbyaddr()  and  gethostbyname()  obsolescent.
    See getaddrinfo(3), getnameinfo(3), gai_strerror(3)."

Daniel
-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|




More information about the libvir-list mailing list