mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2024-07-02 19:08:57 +00:00
Copy hostname for DNS_LOCAL_HOSTLIST_IS_DYNAMIC==1 since string passed to dns_local_addhost() might be volatile
This commit is contained in:
parent
79c88cdcfd
commit
39717b2d9d
|
@ -33,6 +33,10 @@ HISTORY
|
||||||
|
|
||||||
++ Bugfixes:
|
++ 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
|
2010-01-07: Simon Goldschmidt
|
||||||
* timers.c, tcp.h: Call tcp_timer_needed() with NO_SYS==1, too
|
* timers.c, tcp.h: Call tcp_timer_needed() with NO_SYS==1, too
|
||||||
|
|
||||||
|
|
|
@ -337,12 +337,17 @@ dns_init_local()
|
||||||
struct local_hostlist_entry *entry;
|
struct local_hostlist_entry *entry;
|
||||||
/* Dynamic: copy entries from DNS_LOCAL_HOSTLIST_INIT to list */
|
/* Dynamic: copy entries from DNS_LOCAL_HOSTLIST_INIT to list */
|
||||||
struct local_hostlist_entry local_hostlist_init[] = DNS_LOCAL_HOSTLIST_INIT;
|
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++) {
|
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);
|
LWIP_ASSERT("mem-error in dns_init_local", entry != NULL);
|
||||||
if (entry != NULL) {
|
if (entry != NULL) {
|
||||||
struct local_hostlist_entry *init_entry = &local_hostlist_init[i];
|
entry->name = (char*)entry + sizeof(struct local_hostlist_entry);
|
||||||
entry->name = init_entry->name;
|
MEMCPY((char*)entry->name, init_entry->name, namelen);
|
||||||
|
((char*)entry->name)[namelen] = 0;
|
||||||
entry->addr = init_entry->addr;
|
entry->addr = init_entry->addr;
|
||||||
entry->next = local_hostlist_dynamic;
|
entry->next = local_hostlist_dynamic;
|
||||||
local_hostlist_dynamic = entry;
|
local_hostlist_dynamic = entry;
|
||||||
|
@ -428,11 +433,16 @@ err_t
|
||||||
dns_local_addhost(const char *hostname, const struct ip_addr *addr)
|
dns_local_addhost(const char *hostname, const struct ip_addr *addr)
|
||||||
{
|
{
|
||||||
struct local_hostlist_entry *entry;
|
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) {
|
if (entry == NULL) {
|
||||||
return ERR_MEM;
|
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->addr = addr->addr;
|
||||||
entry->next = local_hostlist_dynamic;
|
entry->next = local_hostlist_dynamic;
|
||||||
local_hostlist_dynamic = entry;
|
local_hostlist_dynamic = entry;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user