From c98e299e931fdcf6018fa21954a3cb325bf25f7e Mon Sep 17 00:00:00 2001 From: Hajimu UMEMOTO Date: Thu, 20 Jul 2000 18:49:35 +0000 Subject: [PATCH] Copy canonname for *ahost, into static buffer. Obtained from: KAME Project --- lib/libc/net/rcmd.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/libc/net/rcmd.c b/lib/libc/net/rcmd.c index 6f076ed2ae1d..34d65079cf46 100644 --- a/lib/libc/net/rcmd.c +++ b/lib/libc/net/rcmd.c @@ -30,7 +30,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD$ + * $FreeBSD$ */ #if defined(LIBC_SCCS) && !defined(lint) @@ -58,6 +58,7 @@ static char sccsid[] = "@(#)rcmd.c 8.3 (Berkeley) 3/26/94"; #include #include #endif +#include /* wrapper for KAME-special getnameinfo() */ #ifndef NI_WITHSCOPEID @@ -100,7 +101,8 @@ rcmd_af(ahost, rport, locuser, remuser, cmd, fd2p, af) int s, aport, lport, timo, error; char c; int refused; - char num[8], *ohost; + char num[8]; + static char canonnamebuf[MAXDNAME]; /* is it proper here? */ pid = getpid(); @@ -119,8 +121,12 @@ rcmd_af(ahost, rport, locuser, remuser, cmd, fd2p, af) strerror(errno)); return (-1); } - ohost = *ahost; - *ahost = strdup(res->ai_canonname ? res->ai_canonname : *ahost); + + if (res->ai_canonname + && strlen(res->ai_canonname) + 1 < sizeof(canonnamebuf)) { + strncpy(canonnamebuf, res->ai_canonname, sizeof(canonnamebuf)); + *ahost = canonnamebuf; + } ai = res; refused = 0; oldmask = sigblock(sigmask(SIGURG)); @@ -139,8 +145,6 @@ rcmd_af(ahost, rport, locuser, remuser, cmd, fd2p, af) strerror(errno)); freeaddrinfo(res); sigsetmask(oldmask); - free(*ahost); - *ahost = ohost; return (-1); } _fcntl(s, F_SETOWN, pid); @@ -187,8 +191,6 @@ rcmd_af(ahost, rport, locuser, remuser, cmd, fd2p, af) (void)fprintf(stderr, "%s: %s\n", *ahost, strerror(errno)); freeaddrinfo(res); sigsetmask(oldmask); - free(*ahost); - *ahost = ohost; return (-1); } lport--; @@ -296,8 +298,6 @@ bad: (void)_close(s); sigsetmask(oldmask); freeaddrinfo(res); - free(*ahost); - *ahost = ohost; return (-1); }