Commit 7dec1bf8 authored by Stephen Hemminger's avatar Stephen Hemminger

Fix bad hash calculation because of signed address

The addr[] was being used signed, but this causes hash calcultion
to overflow. Originally reported as Debian bug 480173.
parent 7b3d366e
...@@ -518,13 +518,14 @@ const char *rt_addr_n2a(int af, int len, const void *addr, char *buf, int buflen ...@@ -518,13 +518,14 @@ const char *rt_addr_n2a(int af, int len, const void *addr, char *buf, int buflen
struct namerec struct namerec
{ {
struct namerec *next; struct namerec *next;
const char *name;
inet_prefix addr; inet_prefix addr;
char *name;
}; };
static struct namerec *nht[256]; #define NHASH 257
static struct namerec *nht[NHASH];
char *resolve_address(const char *addr, int len, int af) static const char *resolve_address(const void *addr, int len, int af)
{ {
struct namerec *n; struct namerec *n;
struct hostent *h_ent; struct hostent *h_ent;
...@@ -539,7 +540,7 @@ char *resolve_address(const char *addr, int len, int af) ...@@ -539,7 +540,7 @@ char *resolve_address(const char *addr, int len, int af)
len = 4; len = 4;
} }
hash = addr[len-1] ^ addr[len-2] ^ addr[len-3] ^ addr[len-4]; hash = *(__u32 *)(addr + len - 4) % NHASH;
for (n = nht[hash]; n; n = n->next) { for (n = nht[hash]; n; n = n->next) {
if (n->addr.family == af && if (n->addr.family == af &&
...@@ -573,7 +574,8 @@ const char *format_host(int af, int len, const void *addr, ...@@ -573,7 +574,8 @@ const char *format_host(int af, int len, const void *addr,
{ {
#ifdef RESOLVE_HOSTNAMES #ifdef RESOLVE_HOSTNAMES
if (resolve_hosts) { if (resolve_hosts) {
char *n; const char *n;
if (len <= 0) { if (len <= 0) {
switch (af) { switch (af) {
case AF_INET: case AF_INET:
......
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