Commit e8510bc4 authored by Bernd Eckenfels's avatar Bernd Eckenfels

lib/inet.c: replace safe_strcpy with strdup for dynamically allocated cache, fixes truncation

parent c0d46405
...@@ -157,7 +157,7 @@ static int INET_rresolve(char *name, size_t len, struct sockaddr_in *sin, ...@@ -157,7 +157,7 @@ static int INET_rresolve(char *name, size_t len, struct sockaddr_in *sin,
} }
ad = sin->sin_addr.s_addr; ad = sin->sin_addr.s_addr;
#ifdef DEBUG #ifdef DEBUG
fprintf (stderr, "rresolve: %08lx, mask %08x, num %08x \n", ad, netmask, numeric); fprintf (stderr, "rresolve: %08lx, mask %08x, num %08x, len %d\n", ad, netmask, numeric, len);
#endif #endif
// if no symbolic names are requested we shortcut with ntoa // if no symbolic names are requested we shortcut with ntoa
...@@ -193,7 +193,7 @@ static int INET_rresolve(char *name, size_t len, struct sockaddr_in *sin, ...@@ -193,7 +193,7 @@ static int INET_rresolve(char *name, size_t len, struct sockaddr_in *sin,
if (pn->addr.sin_addr.s_addr == ad && pn->host == host) { if (pn->addr.sin_addr.s_addr == ad && pn->host == host) {
safe_strncpy(name, pn->name, len); safe_strncpy(name, pn->name, len);
#ifdef DEBUG #ifdef DEBUG
fprintf (stderr, "rresolve: found %s %08lx in cache\n", (host? "host": "net"), ad); fprintf (stderr, "rresolve: found %s %08lx in cache (name=%s, len=%d)\n", (host? "host": "net"), ad, name, len);
#endif #endif
return (0); return (0);
} }
...@@ -224,8 +224,7 @@ static int INET_rresolve(char *name, size_t len, struct sockaddr_in *sin, ...@@ -224,8 +224,7 @@ static int INET_rresolve(char *name, size_t len, struct sockaddr_in *sin,
pn->addr = *sin; pn->addr = *sin;
pn->next = INET_nn; pn->next = INET_nn;
pn->host = host; pn->host = host;
pn->name = (char *) xmalloc(strlen(name) + 1); pn->name = strdup(name);
safe_strncpy(pn->name, name, sizeof(pn->name));
INET_nn = pn; INET_nn = pn;
return (0); return (0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment