mirror of
https://github.com/lxsang/ant-http
synced 2025-07-30 04:30:30 +02:00
Race condition when get IP address from host in proxy mode
- ip_from_hostname() is not thread safe - use global lock mechanism
This commit is contained in:
10
lib/utils.c
10
lib/utils.c
@ -605,7 +605,11 @@ int request_socket(const char *ip, int port)
|
||||
{
|
||||
int sockfd;
|
||||
struct sockaddr_in dest;
|
||||
|
||||
if(!ip)
|
||||
{
|
||||
ERROR("Invalid IP address");
|
||||
return -1;
|
||||
}
|
||||
if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
|
||||
{
|
||||
ERROR("Socket: %s", strerror(errno));
|
||||
@ -638,6 +642,10 @@ char* ip_from_hostname(const char *hostname)
|
||||
struct hostent *he;
|
||||
struct in_addr **addr_list;
|
||||
int i;
|
||||
if(!hostname)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
if ((he = gethostbyname(hostname)) == NULL)
|
||||
{
|
||||
// get the host info
|
||||
|
Reference in New Issue
Block a user