Skip to content

Commit

Permalink
hostent_shm_cpy: copy h_name field
Browse files Browse the repository at this point in the history
  • Loading branch information
jes committed Jul 10, 2023
1 parent dc9862f commit 2efbf64
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion proxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,23 @@ int disable_dns_failover=0;

int hostent_shm_cpy(struct hostent *dst, struct hostent* src)
{
unsigned int len;
int i;
char *p;

len = strlen(src->h_name)+1;
dst->h_name = (char*)shm_malloc(sizeof(char) * len);
if (dst->h_name) strncpy(dst->h_name, src->h_name, len);
else return -1;

for( i=0 ; src->h_addr_list[i] ; i++ );

dst->h_addr_list = (char**)shm_malloc
(i * (src->h_length + sizeof(char*)) + sizeof(char*));
if (dst->h_addr_list==NULL)
if (dst->h_addr_list==NULL) {
shm_free(dst->h_name);
return -1;
}

p = ((char*)dst->h_addr_list) + (i+1)*sizeof(char*);
dst->h_addr_list[i] = 0;
Expand All @@ -85,6 +93,8 @@ int hostent_shm_cpy(struct hostent *dst, struct hostent* src)

void free_shm_hostent(struct hostent *dst)
{
if (dst->h_name)
shm_free(dst->h_name);
if (dst->h_addr_list)
shm_free(dst->h_addr_list);
}
Expand Down

0 comments on commit 2efbf64

Please sign in to comment.