gethostbyname doesn't check invalid input

Mikulas Patocka mikulas@artax.karlin.mff.cuni.cz
Tue Oct 2 23:07:00 GMT 2012


Hi

I found a weird thing about gethostbyname and getaddrinfo. When the 
argument is in the form "1.2.3.4 blablabla" (it contains a valid numeric 
ipv4 address, then space and then some garbage), it is correctly resolved 
despite the trailing garbage. If it contains a name, space and garbage, it 
is rejected ("www.gnu.org blabla" doesn't resolve).

What is even more weird - that Linux/glibc, Solaris, NetBSD and HP-UX all 
behave in the same way - they accept a space and a trailing garbage after 
numeric ipv4 address.

Is it a bug or is it correct behavior? Is it specified somewhere? Is there 
some reason for accepting a space and trailing garbage after numeric 
addresses?

Mikulas



More information about the Libc-alpha mailing list