mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-08-05 17:30:27 +00:00
gethostbyname inet_pton fix
when gethostbyname is provided an IP address in the form of a string, it is supposed to write the address to h_name; the function instead was writing an empty string. getaddrinfo does the correct thing by calling inet_pton and returning on success, and the mistake is in gethostbyname. The fix is to strlen(result->ai_canonname): If the inet_pton call in getaddrinfo is successful, ai_canonname will point to valid memory (non-NULL) but the string will be empty. in this case, the name (which is an IP address string) will now correctly be copied to h_name of the hostent structure.
This commit is contained in:
parent
1b9b3864b6
commit
2845e5322f
1 changed files with 1 additions and 1 deletions
|
@ -55,7 +55,7 @@ struct hostent *gethostbyname(const char *name) {
|
|||
if (getaddrinfo(name, NULL, NULL, &result) || result == NULL) return NULL;
|
||||
|
||||
if (ptr0->h_name) free(ptr0->h_name);
|
||||
if (result->ai_canonname) {
|
||||
if (result->ai_canonname && strlen(result->ai_canonname) > 0) {
|
||||
ptr0->h_name = strdup(result->ai_canonname);
|
||||
} else {
|
||||
ptr0->h_name = strdup(name);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue