Copy hostname for DNS_LOCAL_HOSTLIST_IS_DYNAMIC==1 since string passed to dns_local_addhost() might be volatile

This commit is contained in:
goldsimon 2010-01-08 14:42:09 +00:00
parent 79c88cdcfd
commit 39717b2d9d
2 changed files with 19 additions and 5 deletions

View File

@ -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

View File

@ -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;