If gethostbyname_r() fails, the error code is stored in the variable pointed to by the last argument. PR_GetHostByName() uses the value of h_errno as the error code if gethostbyname_r() fails, which is incorrect.
On Red Hat Linux 7.1, if I pass a buffer size of 64 to gethostbyname_r(), the function fails (returning NULL) and sets the following error codes: - h_err: -1 (NETDB_INTERNAL). (The address of h_err is the last argument to gethostbyname_r.) - h_errno: unchanged. - errno: 34 (ERANGE). Looking at <netdb.h>, I believe the intention of setting h_err to -1 is to instruct the caller to check errno for the real error code even though the comments speak of h_errno, which gethostbyname_r() doesn't use. /* Possible values left in `h_errno'. */ #define NETDB_INTERNAL -1 /* See errno. */ The error code ERANGE makes sense for this error because the DNS lookup result is not representable with the given scratch buffer size. #define ERANGE 34 /* Math result not representable */
Reassign to wtc.