diff --git a/modules/dns_cache/dns_cache.c b/modules/dns_cache/dns_cache.c index 901e51ca10..f69a63bc48 100644 --- a/modules/dns_cache/dns_cache.c +++ b/modules/dns_cache/dns_cache.c @@ -150,6 +150,8 @@ static void destroy(void) static int rdata_struct_len=sizeof(struct rdata)-sizeof(void *) - sizeof(struct rdata *); +#define MAXALIASES 36 +#define MAXADDRS 36 static unsigned char *he_buf=NULL; static int he_buf_len=0; static char* serialize_he_rdata(struct hostent *he,int *buf_len,int do_encoding) @@ -165,7 +167,7 @@ static char* serialize_he_rdata(struct hostent *he,int *buf_len,int do_encoding) len+=strlen(he->h_name)+1; if (he->h_aliases) - for (i=0;he->h_aliases[i];i++) { + for (i=0;he->h_aliases[i]&&alias_noh_aliases[i])+1+sizeof(int); alias_no++; @@ -174,7 +176,7 @@ static char* serialize_he_rdata(struct hostent *he,int *buf_len,int do_encoding) i=0; if (he->h_addr_list) - for (i=0;he->h_addr_list[i];i++) { + for (i=0;he->h_addr_list[i]&&addr_noh_length; addr_no++; } @@ -217,7 +219,7 @@ static char* serialize_he_rdata(struct hostent *he,int *buf_len,int do_encoding) /* copy aliases, if any */ if (he->h_aliases) - for (i=0;he->h_aliases[i];i++) { + for (i=0;he->h_aliases[i];i++) { len=strlen(he->h_aliases[i])+1; /* copy alias length */ memcpy(p,&len,sizeof(int)); @@ -233,7 +235,7 @@ static char* serialize_he_rdata(struct hostent *he,int *buf_len,int do_encoding) /* copy addresses */ if (he->h_addr_list) - for (i=0;he->h_addr_list[i];i++) { + for (i=0;he->h_addr_list[i];i++) { /* copy addreses. length will be known from the addrtype field */ len=he->h_length; memcpy(p,he->h_addr_list[i],len); @@ -259,8 +261,6 @@ static char* serialize_he_rdata(struct hostent *he,int *buf_len,int do_encoding) static unsigned char *dec_he_buf=NULL; static int dec_he_buf_len=0; static struct hostent dec_global_he; -#define MAXALIASES 36 -#define MAXADDRS 36 static char *h_addr_ptrs[MAXADDRS]; static char *host_aliases[MAXALIASES]; static struct hostent* deserialize_he_rdata(char *buff,int buf_len,int do_decoding) @@ -289,10 +289,8 @@ static struct hostent* deserialize_he_rdata(char *buff,int buf_len,int do_decodi /* set pointer in dec_global_he */ ap = host_aliases; - *ap = NULL; dec_global_he.h_aliases = host_aliases; hap = h_addr_ptrs; - *hap = NULL; dec_global_he.h_addr_list = h_addr_ptrs; if (do_decoding) { @@ -329,6 +327,7 @@ static struct hostent* deserialize_he_rdata(char *buff,int buf_len,int do_decodi *ap++ = (char *)p; p+=len; } + *ap = NULL; /* get number of addresses */ memcpy(&addr_no,p,sizeof(int)); @@ -339,6 +338,7 @@ static struct hostent* deserialize_he_rdata(char *buff,int buf_len,int do_decodi *hap++ = (char *)p; p+=dec_global_he.h_length; } + *hap = NULL; return &dec_global_he; }