summaryrefslogtreecommitdiffstats
path: root/libexec
diff options
context:
space:
mode:
authoryar <yar@FreeBSD.org>2002-08-20 14:56:06 +0000
committeryar <yar@FreeBSD.org>2002-08-20 14:56:06 +0000
commita5929f9a8823713901e4fb9a3162faa98aa59388 (patch)
tree7e762fe4ed6aa9b786288fafb609f87b79bf3b68 /libexec
parent341b7477e77178c127194a8dc6f88542c946492d (diff)
downloadFreeBSD-src-a5929f9a8823713901e4fb9a3162faa98aa59388.zip
FreeBSD-src-a5929f9a8823713901e4fb9a3162faa98aa59388.tar.gz
Clean up hostname and hostinfo handling in inithosts():
o check getaddrinfo(3) return value, not result pointer o getaddrinfo(3) returns int, not pointer o don't leak memory allocated for hostnames and hostinfo structures o initialize pointers that will be checked for NULL somewhere MFC after: 1 week
Diffstat (limited to 'libexec')
-rw-r--r--libexec/ftpd/ftpd.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/libexec/ftpd/ftpd.c b/libexec/ftpd/ftpd.c
index 7b833b6..9704f60 100644
--- a/libexec/ftpd/ftpd.c
+++ b/libexec/ftpd/ftpd.c
@@ -681,8 +681,7 @@ inithosts(void)
memset(&hints, 0, sizeof(hints));
hints.ai_flags = AI_CANONNAME;
hints.ai_family = AF_UNSPEC;
- getaddrinfo(hrp->hostname, NULL, &hints, &res);
- if (res)
+ if (getaddrinfo(hrp->hostname, NULL, &hints, &res) == 0)
hrp->hostinfo = res;
hrp->statfile = _PATH_FTPDSTATFILE;
hrp->welcome = _PATH_FTPWELCOME;
@@ -754,8 +753,7 @@ inithosts(void)
hints.ai_flags = 0;
hints.ai_family = AF_UNSPEC;
hints.ai_flags = AI_PASSIVE;
- error = getaddrinfo(vhost, NULL, &hints, &res);
- if (error != NULL)
+ if (getaddrinfo(vhost, NULL, &hints, &res) != 0)
goto nextline;
for (ai = res; ai != NULL && ai->ai_addr != NULL;
ai = ai->ai_next) {
@@ -779,9 +777,13 @@ inithosts(void)
if (hrp == NULL) {
if ((hrp = malloc(sizeof(struct ftphost))) == NULL)
goto nextline;
+ hrp->hostname = NULL;
+ hrp->hostinfo = NULL;
insert = 1;
} else
insert = 0; /* host already in the chain */
+ if (hrp->hostinfo)
+ freeaddrinfo(hrp->hostinfo);
hrp->hostinfo = res;
/*
@@ -823,7 +825,13 @@ inithosts(void)
}
}
}
- if ((hrp->hostname = strdup(vhost)) == NULL)
+ if (hrp->hostname &&
+ strcmp(hrp->hostname, vhost) != 0) {
+ free(hrp->hostname);
+ hrp->hostname = NULL;
+ }
+ if (hrp->hostname == NULL &&
+ (hrp->hostname = strdup(vhost)) == NULL)
goto nextline;
hrp->anonuser = anonuser;
hrp->statfile = statfile;
OpenPOWER on IntegriCloud