From 5d0fe6351a1979bbfe6665ccb67376e076d68eec Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Fri, 24 Aug 2001 06:57:53 +0000 Subject: * net.cc (free_addr_list): Add define for symmetry. (free_hostent_ptr): Use free_addr_list to free h_addr_list element. (dup_addr_list): New static function. (dup_hostent_ptr): Use dup_addr_list instead of dup_char_list in order to handle embedded null characters. --- winsup/cygwin/ChangeLog | 11 +++++++++++ winsup/cygwin/net.cc | 26 ++++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) (limited to 'winsup') diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index cb19cbb..87c7c07 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,14 @@ +Fri Aug 24 8:54:00 2001 Corinna Vinschen + + * net.cc (free_addr_list): Add define for symmetry. + (free_hostent_ptr): Use free_addr_list to free h_addr_list element. + +Thu Aug 23 16:00:09 2001 Jason Tishler + + * net.cc (dup_addr_list): New static function. + (dup_hostent_ptr): Use dup_addr_list instead of dup_char_list in order + to handle embedded null characters. + Wed Aug 22 22:23:14 2001 Christopher Faylor * dtable.cc (dtable::dup2): Allow extension of fd table by dup2. diff --git a/winsup/cygwin/net.cc b/winsup/cygwin/net.cc index 19063e9..b9faa1b 100644 --- a/winsup/cygwin/net.cc +++ b/winsup/cygwin/net.cc @@ -409,6 +409,27 @@ dup_char_list (char **src) return dst; } +#define free_addr_list(addr_list) free_char_list (addr_list) + +static char ** +dup_addr_list (char **src, unsigned int size) +{ + char **dst; + int cnt = 0; + + for (char **cl = src; *cl; ++cl) + ++cnt; + if (!(dst = (char **) calloc (cnt + 1, sizeof *dst))) + return NULL; + while (cnt-- > 0) + { + if (!(dst[cnt] = (char *) malloc(size))) + return NULL; + memcpy(dst[cnt], src[cnt], size); + } + return dst; +} + static void free_protoent_ptr (struct protoent *&p) { @@ -998,7 +1019,7 @@ free_hostent_ptr (struct hostent *&p) if (p->h_name) free ((void *)p->h_name); free_char_list (p->h_aliases); - free_char_list (p->h_addr_list); + free_addr_list (p->h_addr_list); p = NULL; } } @@ -1021,7 +1042,8 @@ dup_hostent_ptr (struct hostent *src) goto out; if (src->h_aliases && !(dst->h_aliases = dup_char_list (src->h_aliases))) goto out; - if (src->h_addr_list && !(dst->h_addr_list = dup_char_list(src->h_addr_list))) + if (src->h_addr_list + && !(dst->h_addr_list = dup_addr_list(src->h_addr_list, src->h_length))) goto out; debug_printf ("hostent: copied %s", dst->h_name); -- cgit v1.1