diff --git a/CHANGELOG b/CHANGELOG index d7ece291..909f547b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -33,6 +33,10 @@ HISTORY ++ Bugfixes: + 2010-01-08: Simon Goldschmidt + * dns.c: Copy hostname for DNS_LOCAL_HOSTLIST_IS_DYNAMIC==1 since string + passed to dns_local_addhost() might be volatile + 2010-01-07: Simon Goldschmidt * timers.c, tcp.h: Call tcp_timer_needed() with NO_SYS==1, too diff --git a/src/core/dns.c b/src/core/dns.c index b955538c..cb3d0a68 100644 --- a/src/core/dns.c +++ b/src/core/dns.c @@ -337,12 +337,17 @@ dns_init_local() struct local_hostlist_entry *entry; /* Dynamic: copy entries from DNS_LOCAL_HOSTLIST_INIT to list */ struct local_hostlist_entry local_hostlist_init[] = DNS_LOCAL_HOSTLIST_INIT; + size_t namelen; for (i = 0; i < sizeof(local_hostlist_init) / sizeof(struct local_hostlist_entry); i++) { - entry = mem_malloc(sizeof(struct local_hostlist_entry)); + struct local_hostlist_entry *init_entry = &local_hostlist_init[i]; + LWIP_ASSERT("invalid host name (NULL)", init_entry->name != NULL); + namelen = strlen(init_entry->name); + entry = mem_malloc(sizeof(struct local_hostlist_entry) + namelen + 1); LWIP_ASSERT("mem-error in dns_init_local", entry != NULL); if (entry != NULL) { - struct local_hostlist_entry *init_entry = &local_hostlist_init[i]; - entry->name = init_entry->name; + entry->name = (char*)entry + sizeof(struct local_hostlist_entry); + MEMCPY((char*)entry->name, init_entry->name, namelen); + ((char*)entry->name)[namelen] = 0; entry->addr = init_entry->addr; entry->next = local_hostlist_dynamic; local_hostlist_dynamic = entry; @@ -428,11 +433,16 @@ err_t dns_local_addhost(const char *hostname, const struct ip_addr *addr) { struct local_hostlist_entry *entry; - entry = mem_malloc(sizeof(struct local_hostlist_entry)); + size_t namelen; + LWIP_ASSERT("invalid host name (NULL)", hostname != NULL); + namelen = strlen(hostname); + entry = mem_malloc(sizeof(struct local_hostlist_entry) + namelen + 1); if (entry == NULL) { return ERR_MEM; } - entry->name = hostname; + entry->name = (char*)entry + sizeof(struct local_hostlist_entry); + MEMCPY((char*)entry->name, hostname, namelen); + ((char*)entry->name)[namelen] = 0; entry->addr = addr->addr; entry->next = local_hostlist_dynamic; local_hostlist_dynamic = entry;