summaryrefslogtreecommitdiffstats
path: root/support/export/hostname.c
diff options
context:
space:
mode:
authorchip <chip>2003-09-09 16:01:57 +0000
committerchip <chip>2003-09-09 16:01:57 +0000
commit975a8822c32d969fb2cd6108b3ec8e278f6b0e77 (patch)
tree861f24ee62e6671a07234f55cd701f8587d1cf74 /support/export/hostname.c
parent430052cab3c8044ef6d1be7b5a5ded13c45d0c40 (diff)
downloadnfs-utils-975a8822c32d969fb2cd6108b3ec8e278f6b0e77.tar.gz
nfs-utils-975a8822c32d969fb2cd6108b3ec8e278f6b0e77.tar.xz
nfs-utils-975a8822c32d969fb2cd6108b3ec8e278f6b0e77.zip
* support/export/hostname.c (get_reliable_hostbyaddr): Fix crash
on invalid reverse DNS.
Diffstat (limited to 'support/export/hostname.c')
-rw-r--r--support/export/hostname.c45
1 files changed, 22 insertions, 23 deletions
diff --git a/support/export/hostname.c b/support/export/hostname.c
index f88e0a4..3957d80 100644
--- a/support/export/hostname.c
+++ b/support/export/hostname.c
@@ -224,46 +224,45 @@ matchhostname (const char *h1, const char *h2)
struct hostent *
get_reliable_hostbyaddr(const char *addr, int len, int type)
{
- struct hostent *hp;
+ struct hostent *hp = NULL;
+ struct hostent *reverse;
+ struct hostent *forward;
char **sp;
- struct hostent *forward = NULL;
- char *tmpname;
- hp = gethostbyaddr(addr, len , type);
- if (!hp)
- return hp;
+ reverse = gethostbyaddr (addr, len, type);
+ if (!reverse)
+ return NULL;
/* must make sure the hostent is authorative. */
- hp = hostent_dup (hp);
- tmpname = xstrdup((hp)->h_name);
- if (tmpname) {
- forward = gethostbyname(tmpname);
- free(tmpname);
- }
+ reverse = hostent_dup (reverse);
+ forward = gethostbyname (reverse->h_name);
+
if (forward) {
/* now make sure the "addr" is in the list */
for (sp = forward->h_addr_list ; *sp ; sp++) {
- if (memcmp(*sp, addr, forward->h_length)==0)
+ if (memcmp (*sp, addr, forward->h_length) == 0)
break;
}
-
- if (!*sp) {
+
+ if (*sp) {
+ /* it's valid */
+ hp = hostent_dup (forward);
+ }
+ else {
/* it was a FAKE */
- xlog(L_WARNING, "Fake hostname %s for %s - forward lookup doesn't match reverse",
- forward->h_name, inet_ntoa(*(struct in_addr*)addr));
- return NULL;
+ xlog (L_WARNING, "Fake hostname %s for %s - forward lookup doesn't match reverse",
+ reverse->h_name, inet_ntoa(*(struct in_addr*)addr));
}
- free (hp);
- hp = hostent_dup (forward);
}
else {
/* never heard of it. misconfigured DNS? */
- xlog(L_WARNING, "Fake hostname %s for %s - forward lookup doesn't exist",
- forward->h_name, inet_ntoa(*(struct in_addr*)addr));
- return NULL;
+ xlog (L_WARNING, "Fake hostname %s for %s - forward lookup doesn't exist",
+ reverse->h_name, inet_ntoa(*(struct in_addr*)addr));
}
+
+ free (reverse);
return hp;
}