From 1f6b02c5a30aeb0ad40e2c490bd13805890ab99c Mon Sep 17 00:00:00 2001 From: davidn Date: Mon, 26 Jun 2000 05:36:09 +0000 Subject: Fix a problem in the virtual host address compare code which caused duplicated host entries in /etc/ftphosts not to be folded. Make sure we exit the loop on a match. PR: bin/19390 --- libexec/ftpd/ftpd.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'libexec/ftpd') diff --git a/libexec/ftpd/ftpd.c b/libexec/ftpd/ftpd.c index deea1b9..6c65028 100644 --- a/libexec/ftpd/ftpd.c +++ b/libexec/ftpd/ftpd.c @@ -643,7 +643,7 @@ inithosts() hrp->next = NULL; thishost = firsthost = lhrp = hrp; if ((fp = fopen(_PATH_FTPHOSTS, "r")) != NULL) { - int addrsize, error; + int addrsize, error, gothost; void *addr; struct hostent *hp; @@ -670,9 +670,9 @@ inithosts() if (error != NULL) continue; for (ai = res; ai != NULL && ai->ai_addr != NULL; - ai = ai->ai_next) - { + ai = ai->ai_next) { + gothost = 0; for (hrp = firsthost; hrp != NULL; hrp = hrp->next) { struct addrinfo *hi; @@ -681,8 +681,12 @@ inithosts() if (hi->ai_addrlen == ai->ai_addrlen && memcmp(hi->ai_addr, ai->ai_addr, - ai->ai_addr->sa_len) == 0) + ai->ai_addr->sa_len) == 0) { + gothost++; break; + } + if (gothost) + break; } if (hrp == NULL) { if ((hrp = malloc(sizeof(struct ftphost))) == NULL) @@ -793,8 +797,7 @@ selecthost(su) port = su->su_port; su->su_port = 0; while (hrp != NULL) { - for (hi = hrp->hostinfo; hi != NULL; hi = hi->ai_next) - { + for (hi = hrp->hostinfo; hi != NULL; hi = hi->ai_next) { if (memcmp(su, hi->ai_addr, hi->ai_addrlen) == 0) { thishost = hrp; break; @@ -809,8 +812,8 @@ selecthost(su) break; } #endif - } - hrp = hrp->next; + } + hrp = hrp->next; } su->su_port = port; /* setup static variables as appropriate */ -- cgit v1.1