patch by Mason: fixed bug #35907: lwip_gethostbyname_r returns an invalid h_addr_list

This commit is contained in:
goldsimon 2012-03-20 22:06:32 +01:00
parent 52d41d19d3
commit c6e4b8f829
2 changed files with 11 additions and 7 deletions

View File

@ -76,6 +76,9 @@ HISTORY
++ Bugfixes:
2012-03-20: Simon Goldschmidt (patch by Mason)
* netdb.c: fixed bug #35907: lwip_gethostbyname_r returns an invalid h_addr_list
2012-03-12: Simon Goldschmidt (patch by Bostjan Meglic)
* ppp.c: fixed bug #35809: PPP GetMask(): Compiler warning on big endian,
possible bug on little endian system

View File

@ -49,7 +49,7 @@
/** helper struct for gethostbyname_r to access the char* buffer */
struct gethostbyname_r_helper {
ip_addr_t *addrs;
ip_addr_t *addr_list[2];
ip_addr_t addr;
char *aliases;
};
@ -180,7 +180,7 @@ lwip_gethostbyname_r(const char *name, struct hostent *ret, char *buf,
}
/* first thing to do: set *result to nothing */
*result = NULL;
if ((name == NULL) || (ret == NULL) || (buf == 0)) {
if ((name == NULL) || (ret == NULL) || (buf == NULL)) {
/* not all arguments given */
*h_errnop = EINVAL;
return -1;
@ -197,7 +197,7 @@ lwip_gethostbyname_r(const char *name, struct hostent *ret, char *buf,
hostname = ((char*)h) + sizeof(struct gethostbyname_r_helper);
/* query host IP address */
err = netconn_gethostbyname(name, &(h->addr));
err = netconn_gethostbyname(name, &h->addr);
if (err != ERR_OK) {
LWIP_DEBUGF(DNS_DEBUG, ("lwip_gethostbyname(%s) failed, err=%d\n", name, err));
*h_errnop = HOST_NOT_FOUND;
@ -209,13 +209,14 @@ lwip_gethostbyname_r(const char *name, struct hostent *ret, char *buf,
hostname[namelen] = 0;
/* fill hostent */
h->addrs = &(h->addr);
h->addr_list[0] = &h->addr;
h->addr_list[1] = NULL;
h->aliases = NULL;
ret->h_name = (char*)hostname;
ret->h_aliases = &(h->aliases);
ret->h_name = hostname;
ret->h_aliases = &h->aliases;
ret->h_addrtype = AF_INET;
ret->h_length = sizeof(ip_addr_t);
ret->h_addr_list = (char**)&(h->addrs);
ret->h_addr_list = (char**)&h->addr_list;
/* set result != NULL */
*result = ret;